Allowing config file lines with arbitrary length --- src/config.c +++ src/config.c @@ -100,7 +100,11 @@ static unsigned int get_number(char **from, char *par, char *filename, int linen int readconfig(config_t *config, char *filename, char *section) { int lineno, insection, havesection, sectioncount; - char *p, word[80], line[300], sectname[80]; + char *p, word[80], sectname[80]; + const size_t buf_size = 256; + char *line = (char *) malloc(buf_size); + size_t line_len = buf_size; + size_t len = 0; FILE *fp; if ((fp = fopen(filename, "r")) == NULL) { @@ -120,7 +124,17 @@ int readconfig(config_t *config, char *filename, char *section) } lineno = 0; - while (fgets(line, sizeof(line), fp) != NULL) { + while (fgets(line, line_len, fp) != NULL) { + + len = strlen(line) - 1; + while (!feof(fp) && line[len] != '\n') { + line_len += buf_size; + line = realloc(line, line_len); + if (fgets(line + len + 1, buf_size + 1, fp) == NULL) + break; + len = strlen(line) - 1; + } + lineno++; if ((p = strchr(line, '#')) != NULL) *p = 0; @@ -205,6 +219,7 @@ int readconfig(config_t *config, char *filename, char *section) } } + free(line); fclose (fp); if (*section != 0 && sectioncount == 0) havesection = 1;