From 76f13deb26973a195c45c887d9af2ba9aa9265d1 Mon Sep 17 00:00:00 2001 From: Rolf Kalbermatter Date: Thu, 16 Oct 2003 19:12:49 +0000 Subject: [PATCH] Use INVALID_FILE_ATTRIBUTES to test for failure of GetFileAttributesA/W and not -1 or 0xFFFFFFFF. --- dlls/msvcrt/dir.c | 4 ++-- dlls/msvcrt/file.c | 12 ++++++------ dlls/shell32/shellord.c | 4 ++-- dlls/shell32/shellpath.c | 2 +- dlls/shell32/tests/shlfileop.c | 2 +- dlls/version/install.c | 8 ++++---- dlls/winedos/int21.c | 2 +- dlls/winmm/mmio.c | 2 +- files/file.c | 11 ++++++----- misc/registry.c | 4 ++-- programs/avitools/aviinfo.c | 2 +- programs/avitools/aviplay.c | 2 +- programs/wcmd/directory.c | 2 +- programs/winedbg/source.c | 10 +++++----- programs/winhelp/macro.c | 2 +- 15 files changed, 35 insertions(+), 34 deletions(-) diff --git a/dlls/msvcrt/dir.c b/dlls/msvcrt/dir.c index 4343461a08b..a5ba3da6567 100644 --- a/dlls/msvcrt/dir.c +++ b/dlls/msvcrt/dir.c @@ -900,7 +900,7 @@ void _searchenv(const char* file, const char* env, char *buf) *buf = '\0'; /* Try CWD first */ - if (GetFileAttributesA( file ) != 0xFFFFFFFF) + if (GetFileAttributesA( file ) != INVALID_FILE_ATTRIBUTES) { GetFullPathNameA( file, MAX_PATH, buf, NULL ); /* Sigh. This error is *always* set, regardless of success */ @@ -940,7 +940,7 @@ void _searchenv(const char* file, const char* env, char *buf) strcat(curPath, file); TRACE("Checking for file %s\n", curPath); - if (GetFileAttributesA( curPath ) != 0xFFFFFFFF) + if (GetFileAttributesA( curPath ) != INVALID_FILE_ATTRIBUTES) { strcpy(buf, curPath); MSVCRT__set_errno(ERROR_FILE_NOT_FOUND); diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c index 8ccc0ca37d5..f5484e72169 100644 --- a/dlls/msvcrt/file.c +++ b/dlls/msvcrt/file.c @@ -279,7 +279,7 @@ int _access(const char *filename, int mode) TRACE("(%s,%d) %ld\n",filename,mode,attr); - if (!filename || attr == 0xffffffff) + if (!filename || attr == INVALID_FILE_ATTRIBUTES) { MSVCRT__set_errno(GetLastError()); return -1; @@ -301,7 +301,7 @@ int _waccess(const MSVCRT_wchar_t *filename, int mode) TRACE("(%s,%d) %ld\n",debugstr_w(filename),mode,attr); - if (!filename || attr == 0xffffffff) + if (!filename || attr == INVALID_FILE_ATTRIBUTES) { MSVCRT__set_errno(GetLastError()); return -1; @@ -321,7 +321,7 @@ int _chmod(const char *path, int flags) { DWORD oldFlags = GetFileAttributesA(path); - if (oldFlags != 0x0FFFFFFFF) + if (oldFlags != INVALID_FILE_ATTRIBUTES) { DWORD newFlags = (flags & _S_IWRITE)? oldFlags & ~FILE_ATTRIBUTE_READONLY: oldFlags | FILE_ATTRIBUTE_READONLY; @@ -340,7 +340,7 @@ int _wchmod(const MSVCRT_wchar_t *path, int flags) { DWORD oldFlags = GetFileAttributesW(path); - if (oldFlags != 0x0FFFFFFFF) + if (oldFlags != INVALID_FILE_ATTRIBUTES) { DWORD newFlags = (flags & _S_IWRITE)? oldFlags & ~FILE_ATTRIBUTE_READONLY: oldFlags | FILE_ATTRIBUTE_READONLY; @@ -873,7 +873,7 @@ char *_mktemp(char *pattern) pattern++; do { - if (GetFileAttributesA(retVal) == 0xFFFFFFFF && + if (GetFileAttributesA(retVal) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND) return retVal; *pattern = letter++; @@ -907,7 +907,7 @@ MSVCRT_wchar_t *_wmktemp(MSVCRT_wchar_t *pattern) pattern++; do { - if (GetFileAttributesW(retVal) == 0xFFFFFFFF && + if (GetFileAttributesW(retVal) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND) return retVal; *pattern = letter++; diff --git a/dlls/shell32/shellord.c b/dlls/shell32/shellord.c index 29810e115de..2d00e171197 100644 --- a/dlls/shell32/shellord.c +++ b/dlls/shell32/shellord.c @@ -806,7 +806,7 @@ DWORD WINAPI SHAddToRecentDocs (UINT uFlags,LPCVOID pv) lstrcpyA(old_lnk_name, link_dir); PathAppendA(old_lnk_name, ptr); if (!DeleteFileA(old_lnk_name)) { - if ((attr = GetFileAttributesA(old_lnk_name)) == -1) { + if ((attr = GetFileAttributesA(old_lnk_name)) == INVALID_FILE_ATTRIBUTES) { if ((err = GetLastError()) != ERROR_FILE_NOT_FOUND) { ERR("Delete for %s failed, err=%d, attr=%08lx\n", old_lnk_name, err, attr); @@ -835,7 +835,7 @@ DWORD WINAPI SHAddToRecentDocs (UINT uFlags,LPCVOID pv) PathAppendA(new_lnk_filepath, new_lnk_name); i = 1; olderrormode = SetErrorMode(SEM_FAILCRITICALERRORS); - while (GetFileAttributesA(new_lnk_filepath) != -1) { + while (GetFileAttributesA(new_lnk_filepath) != INVALID_FILE_ATTRIBUTES) { i++; wsprintfA(new_lnk_name, "%s (%u).lnk", doc_name, i); lstrcpyA(new_lnk_filepath, link_dir); diff --git a/dlls/shell32/shellpath.c b/dlls/shell32/shellpath.c index 22d9dfa3fa8..b1e726ce220 100644 --- a/dlls/shell32/shellpath.c +++ b/dlls/shell32/shellpath.c @@ -446,7 +446,7 @@ BOOL WINAPI IsLFNDriveW(LPCWSTR lpszPath) if (!GetVolumeInformationW(lpszPath, NULL, 0, NULL, &fnlen, NULL, NULL, 0)) return FALSE; - return fnlen>12; + return fnlen > 12; } /************************************************************************* diff --git a/dlls/shell32/tests/shlfileop.c b/dlls/shell32/tests/shlfileop.c index 7d9061e8013..ecd46b4a319 100644 --- a/dlls/shell32/tests/shlfileop.c +++ b/dlls/shell32/tests/shlfileop.c @@ -48,7 +48,7 @@ void createTestFile(CHAR *name) BOOL file_exists(CHAR *name) { - return GetFileAttributesA(name) != 0xFFFFFFFF; + return GetFileAttributesA(name) != INVALID_FILE_ATTRIBUTES; } /* initializes the tests */ diff --git a/dlls/version/install.c b/dlls/version/install.c index 295481e029a..d9ae145dcc9 100644 --- a/dlls/version/install.c +++ b/dlls/version/install.c @@ -382,14 +382,14 @@ DWORD WINAPI VerInstallFileA( sprintf(tmpfn,"%s\\%s",pdest,destfilename); tmplast=strlen(pdest)+1; attr = GetFileAttributesA(tmpfn); - if (attr!=-1) { + if (attr != INVALID_FILE_ATTRIBUTES) { if (attr & FILE_ATTRIBUTE_READONLY) { LZClose(hfsrc); return VIF_WRITEPROT; } /* FIXME: check if file currently in use and return VIF_FILEINUSE */ } - attr = -1; + attr = INVALID_FILE_ATTRIBUTES; if (flags & VIFF_FORCEINSTALL) { if (tmpfile[0]) { sprintf(tmpfn,"%s\\%s",pdest,tmpfile); @@ -400,7 +400,7 @@ DWORD WINAPI VerInstallFileA( */ } } - if (attr == -1) { + if (attr == INVALID_FILE_ATTRIBUTES) { char *s; GetTempFileNameA(pdest,"ver",0,tmpfn); /* should not fail ... */ @@ -505,7 +505,7 @@ DWORD WINAPI VerInstallFileA( char curfn[260]; sprintf(curfn,"%s\\%s",curdir,destfilename); - if (-1!=GetFileAttributesA(curfn)) { + if (INVALID_FILE_ATTRIBUTES != GetFileAttributesA(curfn)) { /* FIXME: check if in use ... if it is, VIF_CANNOTDELETECUR */ if (!DeleteFileA(curfn)) xret|=_error2vif(GetLastError())|VIF_CANNOTDELETECUR; diff --git a/dlls/winedos/int21.c b/dlls/winedos/int21.c index fee02e352b2..3c8beb54a0c 100644 --- a/dlls/winedos/int21.c +++ b/dlls/winedos/int21.c @@ -1606,7 +1606,7 @@ static BOOL INT21_FileAttributes( CONTEXT86 *context, MultiByteToWideChar(CP_OEMCP, 0, fileA, -1, fileW, MAX_PATH); result = GetFileAttributesW( fileW ); - if (result == -1) + if (result == INVALID_FILE_ATTRIBUTES) return FALSE; else { diff --git a/dlls/winmm/mmio.c b/dlls/winmm/mmio.c index b02a174c48d..9cbddd49aef 100644 --- a/dlls/winmm/mmio.c +++ b/dlls/winmm/mmio.c @@ -612,7 +612,7 @@ HMMIO MMIO_Open(LPSTR szFileName, MMIOINFO* refmminfo, DWORD dwOpenFlags, if (GetFullPathNameA(szFileName, sizeof(buffer), buffer, NULL) >= sizeof(buffer)) return (HMMIO16)FALSE; - if ((dwOpenFlags & MMIO_EXIST) && (GetFileAttributesA(buffer) == -1)) + if ((dwOpenFlags & MMIO_EXIST) && (GetFileAttributesA(buffer) == INVALID_FILE_ATTRIBUTES)) return (HMMIO)FALSE; strcpy(szFileName, buffer); return (HMMIO)TRUE; diff --git a/files/file.c b/files/file.c index 9b78e2fb520..c366b98b2cd 100644 --- a/files/file.c +++ b/files/file.c @@ -855,11 +855,12 @@ DWORD WINAPI GetFileAttributesW( LPCWSTR name ) if (name == NULL) { SetLastError( ERROR_INVALID_PARAMETER ); - return -1; + return INVALID_FILE_ATTRIBUTES; } if (!DOSFS_GetFullName( name, TRUE, &full_name) ) - return -1; - if (!FILE_Stat( full_name.long_name, &info, NULL )) return -1; + return INVALID_FILE_ATTRIBUTES; + if (!FILE_Stat( full_name.long_name, &info, NULL )) + return INVALID_FILE_ATTRIBUTES; return info.dwFileAttributes; } @@ -870,12 +871,12 @@ DWORD WINAPI GetFileAttributesW( LPCWSTR name ) DWORD WINAPI GetFileAttributesA( LPCSTR name ) { UNICODE_STRING nameW; - DWORD ret = (DWORD)-1; + DWORD ret = INVALID_FILE_ATTRIBUTES; if (!name) { SetLastError( ERROR_INVALID_PARAMETER ); - return (DWORD)-1; + return INVALID_FILE_ATTRIBUTES; } if (RtlCreateUnicodeStringFromAsciiz(&nameW, name)) diff --git a/misc/registry.c b/misc/registry.c index 9d2f077dabb..eb5015744c7 100644 --- a/misc/registry.c +++ b/misc/registry.c @@ -1182,14 +1182,14 @@ static int _get_reg_type(const WCHAR* windir) /* test %windir%/system32/config/system --> winnt */ strcpyW(tmp, windir); strcatW(tmp, nt_reg_pathW); - if(GetFileAttributesW(tmp) != (DWORD)-1) + if(GetFileAttributesW(tmp) != INVALID_FILE_ATTRIBUTES) ret = REG_WINNT; else { /* test %windir%/system.dat --> win95 */ strcpyW(tmp, windir); strcatW(tmp, win9x_reg_pathW); - if(GetFileAttributesW(tmp) != (DWORD)-1) + if(GetFileAttributesW(tmp) != INVALID_FILE_ATTRIBUTES) ret = REG_WIN95; } diff --git a/programs/avitools/aviinfo.c b/programs/avitools/aviinfo.c index 2208bef8ccd..86c22e44ea7 100644 --- a/programs/avitools/aviinfo.c +++ b/programs/avitools/aviinfo.c @@ -64,7 +64,7 @@ HRESULT (WINAPI *fnAVIStreamInfo)(PAVISTREAM iface,AVISTREAMINFO *afi,LONG size) #undef XXT fnAVIFileInit(); - if (-1==GetFileAttributes(cmdline)) { + if (GetFileAttributes(cmdline) == INVALID_FILE_ATTRIBUTES) { fprintf(stderr,"Usage: aviinfo \n"); exit(1); } diff --git a/programs/avitools/aviplay.c b/programs/avitools/aviplay.c index 1ef1a499724..dd6abd3571e 100644 --- a/programs/avitools/aviplay.c +++ b/programs/avitools/aviplay.c @@ -103,7 +103,7 @@ HRESULT (WINAPI *fnAVIStreamGetFrameClose)(PGETFRAME pg); fnAVIFileInit(); - if (-1==GetFileAttributes(cmdline)) { + if (GetFileAttributes(cmdline) == INVALID_FILE_ATTRIBUTES) { fprintf(stderr,"Usage: aviplay \n"); exit(1); } diff --git a/programs/wcmd/directory.c b/programs/wcmd/directory.c index f1e51f144b8..6d1cf922c73 100644 --- a/programs/wcmd/directory.c +++ b/programs/wcmd/directory.c @@ -156,7 +156,7 @@ ULARGE_INTEGER byte_count, file_size; if ((strchr(search_path, '*') == NULL) && (strchr(search_path, '%') == NULL)) { status = GetFileAttributes (search_path); - if ((status != -1) && (status & FILE_ATTRIBUTE_DIRECTORY)) { + if ((status != INVALID_FILE_ATTRIBUTES) && (status & FILE_ATTRIBUTE_DIRECTORY)) { if (search_path[strlen(search_path)-1] == '\\') { strcat (search_path, "*"); } diff --git a/programs/winedbg/source.c b/programs/winedbg/source.c index 559bc5f464a..db3f00fceb9 100644 --- a/programs/winedbg/source.c +++ b/programs/winedbg/source.c @@ -183,11 +183,11 @@ DEBUG_DisplaySource(char * sourcefile, int start, int end) * Crapola. We need to try and open the file. */ status = GetFileAttributes(sourcefile); - if ( status != -1 ) + if ( status != INVALID_FILE_ATTRIBUTES ) { strcpy(tmppath, sourcefile); } - else if ( (status = GetFileAttributes(basename)) != -1 ) + else if ( (status = GetFileAttributes(basename)) != INVALID_FILE_ATTRIBUTES ) { strcpy(tmppath, basename); } @@ -206,7 +206,7 @@ DEBUG_DisplaySource(char * sourcefile, int start, int end) strcat(tmppath, basename); status = GetFileAttributes(tmppath); - if ( status != -1 ) break; + if ( status != INVALID_FILE_ATTRIBUTES ) break; } if ( sl == NULL ) @@ -233,11 +233,11 @@ DEBUG_DisplaySource(char * sourcefile, int start, int end) } else { - status = -1; + status = INVALID_FILE_ATTRIBUTES; strcpy(tmppath, sourcefile); } - if ( status == -1 ) + if ( status == INVALID_FILE_ATTRIBUTES ) { /* * OK, I guess the user doesn't really want to see it diff --git a/programs/winhelp/macro.c b/programs/winhelp/macro.c index 8b39fb2429b..c25d209fed2 100644 --- a/programs/winhelp/macro.c +++ b/programs/winhelp/macro.c @@ -506,7 +506,7 @@ void MACRO_ExtInsertMenu(LPCSTR str1, LPCSTR str2, LPCSTR str3, LONG u1, LONG u2 BOOL MACRO_FileExist(LPCSTR str) { WINE_TRACE("(\"%s\")\n", str); - return GetFileAttributes(str) != 0xFFFFFFFF; + return GetFileAttributes(str) != INVALID_FILE_ATTRIBUTES; } void MACRO_FileOpen(void)