Use INVALID_FILE_ATTRIBUTES to test for failure of

GetFileAttributesA/W and not -1 or 0xFFFFFFFF.
This commit is contained in:
Rolf Kalbermatter 2003-10-16 19:12:49 +00:00 committed by Alexandre Julliard
parent c66b7b0037
commit 76f13deb26
15 changed files with 35 additions and 34 deletions

View file

@ -900,7 +900,7 @@ void _searchenv(const char* file, const char* env, char *buf)
*buf = '\0'; *buf = '\0';
/* Try CWD first */ /* Try CWD first */
if (GetFileAttributesA( file ) != 0xFFFFFFFF) if (GetFileAttributesA( file ) != INVALID_FILE_ATTRIBUTES)
{ {
GetFullPathNameA( file, MAX_PATH, buf, NULL ); GetFullPathNameA( file, MAX_PATH, buf, NULL );
/* Sigh. This error is *always* set, regardless of success */ /* 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); strcat(curPath, file);
TRACE("Checking for file %s\n", curPath); TRACE("Checking for file %s\n", curPath);
if (GetFileAttributesA( curPath ) != 0xFFFFFFFF) if (GetFileAttributesA( curPath ) != INVALID_FILE_ATTRIBUTES)
{ {
strcpy(buf, curPath); strcpy(buf, curPath);
MSVCRT__set_errno(ERROR_FILE_NOT_FOUND); MSVCRT__set_errno(ERROR_FILE_NOT_FOUND);

View file

@ -279,7 +279,7 @@ int _access(const char *filename, int mode)
TRACE("(%s,%d) %ld\n",filename,mode,attr); TRACE("(%s,%d) %ld\n",filename,mode,attr);
if (!filename || attr == 0xffffffff) if (!filename || attr == INVALID_FILE_ATTRIBUTES)
{ {
MSVCRT__set_errno(GetLastError()); MSVCRT__set_errno(GetLastError());
return -1; 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); TRACE("(%s,%d) %ld\n",debugstr_w(filename),mode,attr);
if (!filename || attr == 0xffffffff) if (!filename || attr == INVALID_FILE_ATTRIBUTES)
{ {
MSVCRT__set_errno(GetLastError()); MSVCRT__set_errno(GetLastError());
return -1; return -1;
@ -321,7 +321,7 @@ int _chmod(const char *path, int flags)
{ {
DWORD oldFlags = GetFileAttributesA(path); DWORD oldFlags = GetFileAttributesA(path);
if (oldFlags != 0x0FFFFFFFF) if (oldFlags != INVALID_FILE_ATTRIBUTES)
{ {
DWORD newFlags = (flags & _S_IWRITE)? oldFlags & ~FILE_ATTRIBUTE_READONLY: DWORD newFlags = (flags & _S_IWRITE)? oldFlags & ~FILE_ATTRIBUTE_READONLY:
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); DWORD oldFlags = GetFileAttributesW(path);
if (oldFlags != 0x0FFFFFFFF) if (oldFlags != INVALID_FILE_ATTRIBUTES)
{ {
DWORD newFlags = (flags & _S_IWRITE)? oldFlags & ~FILE_ATTRIBUTE_READONLY: DWORD newFlags = (flags & _S_IWRITE)? oldFlags & ~FILE_ATTRIBUTE_READONLY:
oldFlags | FILE_ATTRIBUTE_READONLY; oldFlags | FILE_ATTRIBUTE_READONLY;
@ -873,7 +873,7 @@ char *_mktemp(char *pattern)
pattern++; pattern++;
do do
{ {
if (GetFileAttributesA(retVal) == 0xFFFFFFFF && if (GetFileAttributesA(retVal) == INVALID_FILE_ATTRIBUTES &&
GetLastError() == ERROR_FILE_NOT_FOUND) GetLastError() == ERROR_FILE_NOT_FOUND)
return retVal; return retVal;
*pattern = letter++; *pattern = letter++;
@ -907,7 +907,7 @@ MSVCRT_wchar_t *_wmktemp(MSVCRT_wchar_t *pattern)
pattern++; pattern++;
do do
{ {
if (GetFileAttributesW(retVal) == 0xFFFFFFFF && if (GetFileAttributesW(retVal) == INVALID_FILE_ATTRIBUTES &&
GetLastError() == ERROR_FILE_NOT_FOUND) GetLastError() == ERROR_FILE_NOT_FOUND)
return retVal; return retVal;
*pattern = letter++; *pattern = letter++;

View file

@ -806,7 +806,7 @@ DWORD WINAPI SHAddToRecentDocs (UINT uFlags,LPCVOID pv)
lstrcpyA(old_lnk_name, link_dir); lstrcpyA(old_lnk_name, link_dir);
PathAppendA(old_lnk_name, ptr); PathAppendA(old_lnk_name, ptr);
if (!DeleteFileA(old_lnk_name)) { 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) { if ((err = GetLastError()) != ERROR_FILE_NOT_FOUND) {
ERR("Delete for %s failed, err=%d, attr=%08lx\n", ERR("Delete for %s failed, err=%d, attr=%08lx\n",
old_lnk_name, err, attr); old_lnk_name, err, attr);
@ -835,7 +835,7 @@ DWORD WINAPI SHAddToRecentDocs (UINT uFlags,LPCVOID pv)
PathAppendA(new_lnk_filepath, new_lnk_name); PathAppendA(new_lnk_filepath, new_lnk_name);
i = 1; i = 1;
olderrormode = SetErrorMode(SEM_FAILCRITICALERRORS); olderrormode = SetErrorMode(SEM_FAILCRITICALERRORS);
while (GetFileAttributesA(new_lnk_filepath) != -1) { while (GetFileAttributesA(new_lnk_filepath) != INVALID_FILE_ATTRIBUTES) {
i++; i++;
wsprintfA(new_lnk_name, "%s (%u).lnk", doc_name, i); wsprintfA(new_lnk_name, "%s (%u).lnk", doc_name, i);
lstrcpyA(new_lnk_filepath, link_dir); lstrcpyA(new_lnk_filepath, link_dir);

View file

@ -446,7 +446,7 @@ BOOL WINAPI IsLFNDriveW(LPCWSTR lpszPath)
if (!GetVolumeInformationW(lpszPath, NULL, 0, NULL, &fnlen, NULL, NULL, 0)) if (!GetVolumeInformationW(lpszPath, NULL, 0, NULL, &fnlen, NULL, NULL, 0))
return FALSE; return FALSE;
return fnlen>12; return fnlen > 12;
} }
/************************************************************************* /*************************************************************************

View file

@ -48,7 +48,7 @@ void createTestFile(CHAR *name)
BOOL file_exists(CHAR *name) BOOL file_exists(CHAR *name)
{ {
return GetFileAttributesA(name) != 0xFFFFFFFF; return GetFileAttributesA(name) != INVALID_FILE_ATTRIBUTES;
} }
/* initializes the tests */ /* initializes the tests */

View file

@ -382,14 +382,14 @@ DWORD WINAPI VerInstallFileA(
sprintf(tmpfn,"%s\\%s",pdest,destfilename); sprintf(tmpfn,"%s\\%s",pdest,destfilename);
tmplast=strlen(pdest)+1; tmplast=strlen(pdest)+1;
attr = GetFileAttributesA(tmpfn); attr = GetFileAttributesA(tmpfn);
if (attr!=-1) { if (attr != INVALID_FILE_ATTRIBUTES) {
if (attr & FILE_ATTRIBUTE_READONLY) { if (attr & FILE_ATTRIBUTE_READONLY) {
LZClose(hfsrc); LZClose(hfsrc);
return VIF_WRITEPROT; return VIF_WRITEPROT;
} }
/* FIXME: check if file currently in use and return VIF_FILEINUSE */ /* FIXME: check if file currently in use and return VIF_FILEINUSE */
} }
attr = -1; attr = INVALID_FILE_ATTRIBUTES;
if (flags & VIFF_FORCEINSTALL) { if (flags & VIFF_FORCEINSTALL) {
if (tmpfile[0]) { if (tmpfile[0]) {
sprintf(tmpfn,"%s\\%s",pdest,tmpfile); sprintf(tmpfn,"%s\\%s",pdest,tmpfile);
@ -400,7 +400,7 @@ DWORD WINAPI VerInstallFileA(
*/ */
} }
} }
if (attr == -1) { if (attr == INVALID_FILE_ATTRIBUTES) {
char *s; char *s;
GetTempFileNameA(pdest,"ver",0,tmpfn); /* should not fail ... */ GetTempFileNameA(pdest,"ver",0,tmpfn); /* should not fail ... */
@ -505,7 +505,7 @@ DWORD WINAPI VerInstallFileA(
char curfn[260]; char curfn[260];
sprintf(curfn,"%s\\%s",curdir,destfilename); 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 */ /* FIXME: check if in use ... if it is, VIF_CANNOTDELETECUR */
if (!DeleteFileA(curfn)) if (!DeleteFileA(curfn))
xret|=_error2vif(GetLastError())|VIF_CANNOTDELETECUR; xret|=_error2vif(GetLastError())|VIF_CANNOTDELETECUR;

View file

@ -1606,7 +1606,7 @@ static BOOL INT21_FileAttributes( CONTEXT86 *context,
MultiByteToWideChar(CP_OEMCP, 0, fileA, -1, fileW, MAX_PATH); MultiByteToWideChar(CP_OEMCP, 0, fileA, -1, fileW, MAX_PATH);
result = GetFileAttributesW( fileW ); result = GetFileAttributesW( fileW );
if (result == -1) if (result == INVALID_FILE_ATTRIBUTES)
return FALSE; return FALSE;
else else
{ {

View file

@ -612,7 +612,7 @@ HMMIO MMIO_Open(LPSTR szFileName, MMIOINFO* refmminfo, DWORD dwOpenFlags,
if (GetFullPathNameA(szFileName, sizeof(buffer), buffer, NULL) >= sizeof(buffer)) if (GetFullPathNameA(szFileName, sizeof(buffer), buffer, NULL) >= sizeof(buffer))
return (HMMIO16)FALSE; return (HMMIO16)FALSE;
if ((dwOpenFlags & MMIO_EXIST) && (GetFileAttributesA(buffer) == -1)) if ((dwOpenFlags & MMIO_EXIST) && (GetFileAttributesA(buffer) == INVALID_FILE_ATTRIBUTES))
return (HMMIO)FALSE; return (HMMIO)FALSE;
strcpy(szFileName, buffer); strcpy(szFileName, buffer);
return (HMMIO)TRUE; return (HMMIO)TRUE;

View file

@ -855,11 +855,12 @@ DWORD WINAPI GetFileAttributesW( LPCWSTR name )
if (name == NULL) if (name == NULL)
{ {
SetLastError( ERROR_INVALID_PARAMETER ); SetLastError( ERROR_INVALID_PARAMETER );
return -1; return INVALID_FILE_ATTRIBUTES;
} }
if (!DOSFS_GetFullName( name, TRUE, &full_name) ) if (!DOSFS_GetFullName( name, TRUE, &full_name) )
return -1; return INVALID_FILE_ATTRIBUTES;
if (!FILE_Stat( full_name.long_name, &info, NULL )) return -1; if (!FILE_Stat( full_name.long_name, &info, NULL ))
return INVALID_FILE_ATTRIBUTES;
return info.dwFileAttributes; return info.dwFileAttributes;
} }
@ -870,12 +871,12 @@ DWORD WINAPI GetFileAttributesW( LPCWSTR name )
DWORD WINAPI GetFileAttributesA( LPCSTR name ) DWORD WINAPI GetFileAttributesA( LPCSTR name )
{ {
UNICODE_STRING nameW; UNICODE_STRING nameW;
DWORD ret = (DWORD)-1; DWORD ret = INVALID_FILE_ATTRIBUTES;
if (!name) if (!name)
{ {
SetLastError( ERROR_INVALID_PARAMETER ); SetLastError( ERROR_INVALID_PARAMETER );
return (DWORD)-1; return INVALID_FILE_ATTRIBUTES;
} }
if (RtlCreateUnicodeStringFromAsciiz(&nameW, name)) if (RtlCreateUnicodeStringFromAsciiz(&nameW, name))

View file

@ -1182,14 +1182,14 @@ static int _get_reg_type(const WCHAR* windir)
/* test %windir%/system32/config/system --> winnt */ /* test %windir%/system32/config/system --> winnt */
strcpyW(tmp, windir); strcpyW(tmp, windir);
strcatW(tmp, nt_reg_pathW); strcatW(tmp, nt_reg_pathW);
if(GetFileAttributesW(tmp) != (DWORD)-1) if(GetFileAttributesW(tmp) != INVALID_FILE_ATTRIBUTES)
ret = REG_WINNT; ret = REG_WINNT;
else else
{ {
/* test %windir%/system.dat --> win95 */ /* test %windir%/system.dat --> win95 */
strcpyW(tmp, windir); strcpyW(tmp, windir);
strcatW(tmp, win9x_reg_pathW); strcatW(tmp, win9x_reg_pathW);
if(GetFileAttributesW(tmp) != (DWORD)-1) if(GetFileAttributesW(tmp) != INVALID_FILE_ATTRIBUTES)
ret = REG_WIN95; ret = REG_WIN95;
} }

View file

@ -64,7 +64,7 @@ HRESULT (WINAPI *fnAVIStreamInfo)(PAVISTREAM iface,AVISTREAMINFO *afi,LONG size)
#undef XXT #undef XXT
fnAVIFileInit(); fnAVIFileInit();
if (-1==GetFileAttributes(cmdline)) { if (GetFileAttributes(cmdline) == INVALID_FILE_ATTRIBUTES) {
fprintf(stderr,"Usage: aviinfo <avifilename>\n"); fprintf(stderr,"Usage: aviinfo <avifilename>\n");
exit(1); exit(1);
} }

View file

@ -103,7 +103,7 @@ HRESULT (WINAPI *fnAVIStreamGetFrameClose)(PGETFRAME pg);
fnAVIFileInit(); fnAVIFileInit();
if (-1==GetFileAttributes(cmdline)) { if (GetFileAttributes(cmdline) == INVALID_FILE_ATTRIBUTES) {
fprintf(stderr,"Usage: aviplay <avifilename>\n"); fprintf(stderr,"Usage: aviplay <avifilename>\n");
exit(1); exit(1);
} }

View file

@ -156,7 +156,7 @@ ULARGE_INTEGER byte_count, file_size;
if ((strchr(search_path, '*') == NULL) && (strchr(search_path, '%') == NULL)) { if ((strchr(search_path, '*') == NULL) && (strchr(search_path, '%') == NULL)) {
status = GetFileAttributes (search_path); 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] == '\\') { if (search_path[strlen(search_path)-1] == '\\') {
strcat (search_path, "*"); strcat (search_path, "*");
} }

View file

@ -183,11 +183,11 @@ DEBUG_DisplaySource(char * sourcefile, int start, int end)
* Crapola. We need to try and open the file. * Crapola. We need to try and open the file.
*/ */
status = GetFileAttributes(sourcefile); status = GetFileAttributes(sourcefile);
if ( status != -1 ) if ( status != INVALID_FILE_ATTRIBUTES )
{ {
strcpy(tmppath, sourcefile); strcpy(tmppath, sourcefile);
} }
else if ( (status = GetFileAttributes(basename)) != -1 ) else if ( (status = GetFileAttributes(basename)) != INVALID_FILE_ATTRIBUTES )
{ {
strcpy(tmppath, basename); strcpy(tmppath, basename);
} }
@ -206,7 +206,7 @@ DEBUG_DisplaySource(char * sourcefile, int start, int end)
strcat(tmppath, basename); strcat(tmppath, basename);
status = GetFileAttributes(tmppath); status = GetFileAttributes(tmppath);
if ( status != -1 ) break; if ( status != INVALID_FILE_ATTRIBUTES ) break;
} }
if ( sl == NULL ) if ( sl == NULL )
@ -233,11 +233,11 @@ DEBUG_DisplaySource(char * sourcefile, int start, int end)
} }
else else
{ {
status = -1; status = INVALID_FILE_ATTRIBUTES;
strcpy(tmppath, sourcefile); strcpy(tmppath, sourcefile);
} }
if ( status == -1 ) if ( status == INVALID_FILE_ATTRIBUTES )
{ {
/* /*
* OK, I guess the user doesn't really want to see it * OK, I guess the user doesn't really want to see it

View file

@ -506,7 +506,7 @@ void MACRO_ExtInsertMenu(LPCSTR str1, LPCSTR str2, LPCSTR str3, LONG u1, LONG u2
BOOL MACRO_FileExist(LPCSTR str) BOOL MACRO_FileExist(LPCSTR str)
{ {
WINE_TRACE("(\"%s\")\n", str); WINE_TRACE("(\"%s\")\n", str);
return GetFileAttributes(str) != 0xFFFFFFFF; return GetFileAttributes(str) != INVALID_FILE_ATTRIBUTES;
} }
void MACRO_FileOpen(void) void MACRO_FileOpen(void)