Diff options
Diffstat (limited to 'source/config.c')
| -rw-r--r-- | source/config.c | 8 |
1 file changed, 7 insertions, 1 deletion
diff --git a/source/config.c b/source/config.c index bfd31b6..84c7293 100644 --- a/source/config.c +++ b/source/config.c @@ -103,6 +103,7 @@ int config_file_parse(const char *filename, config_file_value_fn fn) int outer_lines_read = lines_read; struct strbuf name = STRBUF_INIT; struct strbuf value = STRBUF_INIT; + struct stat st; FILE *f; int err = 0; @@ -112,12 +113,17 @@ int config_file_parse(const char *filename, config_file_value_fn fn) return 0; if (!(f = fopen(filename, "r"))) return errno; + // Git's fopen refuses a directory only where its build defines + // FREAD_READS_DIRECTORIES, and elsewhere read(2) need not fail on one. + if (!fstat(fileno(f), &st) && S_ISDIR(st.st_mode)) { + fclose(f); + return EISDIR; + } config_origin.file = filename; lines_read = 0; nesting++; while (read_entry(f, &name, &value, &config_origin.line)) fn(name.buf, value.buf); - // A directory opens like a file and fails only once it is read. if (ferror(f)) err = errno; nesting--; |
