static int parse(struct options *opts, FILE *fp) { char *p, arg[MAX_LEN]; int line = 0, ret = 0, err = 0; memset(arg, 0, MAX_LEN); while (!feof(fp) && (ret = fscanf(fp, "\n%256[^\n]\n", arg)) != 0 && ret < MAX_LEN) { line++; if (is_comment(arg)) continue; p = strstr(arg, "="); if (p == NULL) break_line(ERR_SYNTAX, line); *p = '\0'; p++; p = trim(p); if (*p == 0) break_line(ERR_SYNTAX, line); err = try_set_value(p, trim(arg), opts); if (err > 0) break_line(err, line); } if (ret > MAX_LEN) { jlog(L_NOTICE, "option]> the line %i is longer than %i :: %s:%i", line, MAX_LEN, __FILE__, __LINE__); return ERR_ERRNO; } if (ret == EOF) { jlog(L_NOTICE, "option]> unexpected error %s :: %s:%i", strerror(errno), __FILE__, __LINE__); return ERR_ERRNO; } return 0; }
static int parse(struct options *opts, FILE *fp) { journal_strace("parse"); char *p, arg[MAX_LEN]; int line = 0, ret = 0, err = 0; memset(arg, 0, MAX_LEN); /* XXX What if a line is longer than 256 ? */ while (!feof(fp) && (ret = fscanf(fp, "\n%255[^\n]\n", arg)) != 0) { line++; if (is_comment(arg)) continue; p = strstr(arg, "="); if (p == NULL) break_line(ERR_SYNTAX, line); *p = '\0'; p++; p = trim(p); if (*p == 0) break_line(ERR_SYNTAX, line); err = try_set_value(p, trim(arg), opts); if (err > 0) break_line(err, line); } if (ret == 0) /* fscanf() failed */ return ERR_ERRNO; return 0; }