Skip to content

Commit

Permalink
Remove readFileNumber function
Browse files Browse the repository at this point in the history
  • Loading branch information
tvegas1 committed Nov 7, 2023
1 parent 08dd346 commit 61cf1a2
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 55 deletions.
1 change: 0 additions & 1 deletion include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ struct netIf {

int parseStringList(const char* string, struct netIf* ifList, int maxList);
int matchIfList(const char* string, int port, struct netIf* ifList, int listSize, int matchExact);
int readFileNumber(long *value, const char *filename_fmt, ...);
const char *get_plugin_lib_path();

#endif
54 changes: 0 additions & 54 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,60 +110,6 @@ int matchIfList(const char* string, int port, struct netIf* ifList, int listSize
return 0;
}

static size_t readFileVarArg(char *buffer, size_t max,
const char *filename_fmt, va_list ap)
{
char filename[PATH_MAX];
ssize_t read_bytes;
int fd;

vsnprintf(filename, PATH_MAX, filename_fmt, ap);

fd = open(filename, O_RDONLY);
if (fd < 0) {
return -1;
}

read_bytes = read(fd, buffer, max - 1);
if (read_bytes < 0) {
return -1;
}

if (read_bytes < max) {
buffer[read_bytes] = '\0';
}

out_close:
close(fd);
}

int readFileNumber(long *value, const char *filename_fmt, ...)
{
char buffer[64], *tail;
ssize_t read_bytes;
va_list ap;
long n;

va_start(ap, filename_fmt);
read_bytes = readFileVarArg(buffer, sizeof(buffer) - 1,
filename_fmt, ap);
va_end(ap);

if (read_bytes < 0) {
/* read error */
return -1;
}

n = strtol(buffer, &tail, 0);
if ((*tail != '\0') && !isspace(*tail)) {
/* parse error */
return -1;
}

*value = n;
return 0;
}

const char *get_plugin_lib_path()
{
Dl_info dl_info;
Expand Down

0 comments on commit 61cf1a2

Please sign in to comment.