config.c: rewrite ENODEV into EISDIR when mmap fails

If we try to mmap a directory, we'll get ENODEV. This translates to "no such device" for the user, which is not very helpful. Since we've just fstat()'d the file, we can easily check whether the problem was a directory to give a better message. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed May 28, 2015 at 04:03 UTC 0e8771f1984c468b0f41a8c779c034ffc48530e5
1 file changed +2
config.c
+2
@@ -2051,6 +2051,8 @@ int git_config_set_multivar_in_file(const char *config_filename,
2051 contents = xmmap_gently(NULL, contents_sz, PROT_READ,
2052 MAP_PRIVATE, in_fd, 0);
2053 if (contents == MAP_FAILED) {
2054 + if (errno == ENODEV && S_ISDIR(st.st_mode))
2055 + errno = EISDIR;
2056 error("unable to mmap '%s': %s",
2057 config_filename, strerror(errno));
2058 ret = CONFIG_INVALID_FILE;