From 65eabed2e1c07c3b1c8a8beb2a42676a45783897 Mon Sep 17 00:00:00 2001 From: Victor Perevertkin Date: Sun, 25 Mar 2018 00:33:57 +0300 Subject: [PATCH] [CRT] Fixed _tstat64 which wrongly set executable bits on files. CORE-10904 Replaced some string functions with their tchar.h analogs --- sdk/lib/crt/stdio/stat64.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/sdk/lib/crt/stdio/stat64.c b/sdk/lib/crt/stdio/stat64.c index 98e63c57fbe..26feb528a5d 100644 --- a/sdk/lib/crt/stdio/stat64.c +++ b/sdk/lib/crt/stdio/stat64.c @@ -16,29 +16,28 @@ inline void release_ioinfo(ioinfo *info); #define TCHAR4 ULONG #endif -#define TCSIZE sizeof(_TCHAR) -#define TOULL(x) ((TCHAR4)(x)) +#define TCSIZE_BITS (sizeof(_TCHAR)*8) -#define EXE ((TOULL('e')<<(2*TCSIZE)) | (TOULL('x')<st_dev = buf->st_rdev = toupper(*path) - 'A'; /* drive num */ + if (_istalpha(*path) && (*(path+1)==__T(':'))) + buf->st_dev = buf->st_rdev = _totupper(*path) - __T('A'); /* drive num */ else buf->st_dev = buf->st_rdev = _getdrive() - 1; @@ -70,10 +69,13 @@ int CDECL _tstat64(const _TCHAR *path, struct __stat64 *buf) { mode |= _S_IFREG; /* executable? */ - if (plen > 6 && path[plen-4] == '.') /* shortest exe: "\x.exe" */ + if (plen > 6 && path[plen-4] == __T('.')) /* shortest exe: "\x.exe" */ { - unsigned int ext = tolower(path[plen-1]) | (tolower(path[plen-2]) << 8) | - (tolower(path[plen-3]) << 16); + + TCHAR4 ext = (TCHAR4)_totlower(path[plen-1]) + | ((TCHAR4)_totlower(path[plen-2]) << TCSIZE_BITS) + | ((TCHAR4)_totlower(path[plen-3]) << 2*TCSIZE_BITS); + if (ext == EXE || ext == BAT || ext == CMD || ext == COM) mode |= ALL_S_IEXEC; }