diff options
author | H. Peter Anvin <hpa@zytor.com> | 2019-10-03 20:55:56 -0700 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2019-10-03 20:58:21 -0700 |
commit | c6666be781f6ceab0223386822109eea0631cdff (patch) | |
tree | 4829517dcf17cc98779946c56daa1470cac462a2 | |
parent | 0209ecb179d48d4a703444a919687cd36f378577 (diff) | |
download | nasm-c6666be781f6ceab0223386822109eea0631cdff.tar.gz |
Win32: when converting filenames to UTF-16, don't add \\?\
\\?\ is supposed to override the hard-coded path limit, but it has
other effects as well, such as not working with relative paths and
paths containing /. On Windows 10 it is possible to set a registry key
to override this option anyway.
Maybe one day we can just use fopen() like on normal systems, even...
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Link: https://bugzilla.nasm.us/show_bug.cgi?id=3392614
Reported-by: Iouri Kharon <bc-info@styx.cabel.net>
-rw-r--r-- | nasmlib/file.c | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/nasmlib/file.c b/nasmlib/file.c index e2e6c553..e5c0e335 100644 --- a/nasmlib/file.c +++ b/nasmlib/file.c @@ -105,9 +105,14 @@ void fwritezero(off_t bytes, FILE *fp) /* * On Windows, we want to use _wfopen(), as fopen() has a much smaller limit - * on the path length that it supports. Furthermore, we want to prefix the - * path name with \\?\ in order to let the Windows kernel know that - * we are not limited to PATH_MAX characters. + * on the path length that it supports. + * + * Previously we tried to prefix the path name with \\?\ in order to + * let the Windows kernel know that we are not limited to PATH_MAX + * characters, but it breaks relative paths among other things, and + * apparently Windows 10 contains a registry option to override this + * limit anyway. One day maybe they will even implement UTF-8 as byte + * characters so we can use the standard file API even on this OS. */ os_filename os_mangle_filename(const char *filename) @@ -117,13 +122,6 @@ os_filename os_mangle_filename(const char *filename) wchar_t *buf; const char *p; - /* If the filename is already prefixed with \\?\, don't add it again */ - if ((filename[0] == '\\' || filename[0] == '/') && - (filename[1] == '\\' || filename[1] == '/') && - filename[2] == '?' && - (filename[3] == '\\' || filename[3] == '/')) - filename += 4; - /* * Note: mbsrtowcs() return (size_t)-1 on error, otherwise * the length of the string *without* final NUL in wchar_t @@ -136,12 +134,11 @@ os_filename os_mangle_filename(const char *filename) if (!wclen) return NULL; - buf = nasm_malloc((wclen+4) * sizeof(wchar_t)); - memcpy(buf, L"\\\\?\\", 4*sizeof(wchar_t)); + buf = nasm_malloc(wclen * sizeof(wchar_t)); memset(&ps, 0, sizeof ps); /* Begin in the initial state */ p = filename; - if (mbsrtowcs(buf+4, &p, wclen, &ps) + 1 != wclen || p) { + if (mbsrtowcs(buf, &p, wclen, &ps) + 1 != wclen || p) { nasm_free(buf); return NULL; } |