Merge pull request #3400 from ianyfan/config-brace

config.c: fix brace detection at end of file
This commit is contained in:
emersion 2019-01-10 13:29:21 +01:00 committed by GitHub
commit 212baf2f75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 4 deletions

View File

@ -597,6 +597,7 @@ static ssize_t getline_with_cont(char **lineptr, size_t *line_size, FILE *file)
} }
static int detect_brace(FILE *file) { static int detect_brace(FILE *file) {
int ret = 0;
int lines = 0; int lines = 0;
long pos = ftell(file); long pos = ftell(file);
char *line = NULL; char *line = NULL;
@ -605,15 +606,15 @@ static int detect_brace(FILE *file) {
lines++; lines++;
strip_whitespace(line); strip_whitespace(line);
if (*line) { if (*line) {
if (strcmp(line, "{") != 0) { if (strcmp(line, "{") == 0) {
fseek(file, pos, SEEK_SET); ret = lines;
lines = 0;
} }
break; break;
} }
} }
free(line); free(line);
return lines; fseek(file, pos, SEEK_SET);
return ret;
} }
static char *expand_line(const char *block, const char *line, bool add_brace) { static char *expand_line(const char *block, const char *line, bool add_brace) {