BUG: _stat Function Fails for Names Ending with "\"Last reviewed: May 21, 1997Article ID: Q168439 |
The information in this article applies to:
SYMPTOMSUsing the C-Run-time function stat to check a directory fails when the name passed to the function ends with "\". For example, _stat("\\my_directory\\my_name",&buf) returns OK, but _stat("\\my_directory\\my_name\\",&buf) will return -1 as error.
CAUSEThe _stat function calls the windows API function FindFirstFile passing it the path name. The FindFirstFile returns an invalid handle if the name ends with "\."
RESOLUTIONRemove the trailing "\" from the path name.
STATUSMicrosoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.
MORE INFORMATIONThe following Sample program demonstrates the problem:
//Sample.cpp /* Compiler Options : none */ #include <sys/types.h> #include <sys/stat.h> #include <stdio.h> #include <windows.h> HANDLE hSearch; WIN32_FIND_DATA Buf; int main( void ) { struct _stat buf; int result; result = _stat( "c:\\temp", &buf ); if( result != 0 ) printf( "_stat function on c:\\temp failed " ); result = _stat( "c:\\temp\\", &buf ); if( result != 0 ) printf( "_stat function on c:\\temp\\ failed " ); hSearch= FindFirstFile((LPSTR)"c:\\temp", &Buf); if (hSearch == INVALID_HANDLE_VALUE ) printf("\n\n FindFirstFile on c:\\temp failed too"); hSearch= FindFirstFile((LPSTR)"c:\\temp\\", &Buf); if (hSearch == INVALID_HANDLE_VALUE ) printf("\n\n FindFirstFile on c:\\temp\\ failed too"); return 0; }Program Output: If you have a valid C:\temp directory: _stat function on c:\temp\ failed.
FindFirstFile on c:\temp\ failed, too. REFERENCESOnline docs on _stat CRT function mk:@ivt:vccore/F3F/F43/D4D/S4CF6A.HTM Online docs on FindFirstFile API function mk:@ivt:pdref/native/sdk/win32/func/src/f24_10.htm |
Keywords : CRTIss vcbuglist500 kbbuglist
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |