static int get_file_size(const char *value, unsigned long *dest, const char *config_path, int line) { // Store in bytes, allow k/m/g. const char *cp=NULL; *dest=strtoul(value, NULL, 10); for(cp=value; *cp && (isspace(*cp) || isdigit(*cp)); cp++) { } if(tolower(*cp)=='k') *dest*=1024; else if(tolower(*cp)=='m') *dest*=1024*1024; else if(tolower(*cp)=='g') *dest*=1024*1024*1024; else if(!*cp || *cp=='b') { } else { logp("Unknown file size type '%s' - please use b/kb/mb/gb\n", cp); return conf_error(config_path, line); } return 0; }
static int conf_load_lines_from_file(const char *conf_path, struct conf **confs) { int ret=0; int line=0; FILE *fp=NULL; char buf[4096]=""; if(!(fp=fopen(conf_path, "r"))) { logp("could not open '%s' for reading.\n", conf_path); return -1; } while(fgets(buf, sizeof(buf), fp)) { line++; if(conf_parse_line(confs, conf_path, buf, line)) { conf_error(conf_path, line); ret=-1; } } if(fp) fclose(fp); return ret; }