Read config parameters

pull/23/head
Gerard Wagener 2018-11-27 15:19:40 +01:00
parent 5e1cbfff30
commit 9bfc03f5c6
1 changed files with 13 additions and 0 deletions

View File

@ -3,17 +3,30 @@
#include <stdint.h> #include <stdint.h>
#include <getopt.h> #include <getopt.h>
#include <string.h> #include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include "d4.h" #include "d4.h"
//Returns -1 on error, 0 otherwise //Returns -1 on error, 0 otherwise
int d4_load_config(d4_t* d4) int d4_load_config(d4_t* d4)
{ {
int i; int i;
int fd;
char *buf; char *buf;
buf=calloc(1,2*FILENAME_MAX); buf=calloc(1,2*FILENAME_MAX);
if (buf) { if (buf) {
for (i=0; i < ND4PARAMS; i++) { for (i=0; i < ND4PARAMS; i++) {
snprintf(buf,2*FILENAME_MAX, "%s/%s",d4->confdir, d4params[i]); snprintf(buf,2*FILENAME_MAX, "%s/%s",d4->confdir, d4params[i]);
fd = open(buf,O_RDONLY);
if (fd) {
//FIXME error handling
read(fd, d4->conf[i], SZCONFVALUE);
} else {
d4->errno_copy = errno;
}
} }
} }
return -1; return -1;