mingw_fopen: report ENOENT for invalid file names

On Windows, certain characters are prohibited in file names, most prominently the colon. When fopen() is called with such an invalid file name, the underlying Windows API actually reports a particular error, but since there is no suitable errno value, this error is translated to EINVAL. Detect the case and report ENOENT instead. Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Sixt committed May 29, 2017 at 22:27 UTC e5b313442ab7c700d0851e9dbe7d2b029e3893e5
2 files changed +3 -1
compat/mingw.c
+2
@@ -423,6 +423,8 @@ FILE *mingw_fopen (const char *filename, const char *otype)
423 return NULL;
424 }
425 file = _wfopen(wfilename, wotype);
426 + if (!file && GetLastError() == ERROR_INVALID_NAME)
427 + errno = ENOENT;
428 if (file && hide && set_hidden_flag(wfilename, 1))
429 warning("could not mark '%s' as hidden.", filename);
430 return file;
t/t5580-clone-push-unc.sh
+1 -1
@@ -45,7 +45,7 @@ test_expect_success push '
45 test "$rev" = "$(git rev-parse --verify refs/heads/to-push)"
46 '
47
48 -test_expect_failure 'remote nick cannot contain backslashes' '
48 +test_expect_success 'remote nick cannot contain backslashes' '
49 BACKSLASHED="$(pwd | tr / \\\\)" &&
50 git ls-remote "$BACKSLASHED" >out 2>err &&
51 test_i18ngrep ! "unable to access" err