Removed hacks from findfirst/findnext APIs

See issue #1736 for more details.

svn path=/trunk/; revision=27847
This commit is contained in:
Thomas Bluemel 2007-07-26 15:07:07 +00:00
parent 4473df2e66
commit bf93eab031

View file

@ -12,24 +12,10 @@ int
_tfindfirst(const _TCHAR* _name, struct _tfinddata_t* result)
{
WIN32_FIND_DATA FindFileData;
_TCHAR dir[MAX_PATH];
long hFindFile;
int len = 0;
if (_name == NULL || _name[0] == 0) {
len = GetCurrentDirectory(MAX_PATH-4,dir);
if (dir[len-1] != '\\') {
dir[len] = '\\';
dir[len+1] = 0;
}
_tcscat(dir,_T("*.*"));
} else {
_tcscpy(dir,_name);
}
hFindFile = (long)FindFirstFile(dir, &FindFileData);
hFindFile = (long)FindFirstFile(_name, &FindFileData);
if (hFindFile == -1) {
memset(result,0,sizeof(struct _tfinddata_t));
_dosmaperr(GetLastError());
return -1;
}
@ -41,14 +27,6 @@ _tfindfirst(const _TCHAR* _name, struct _tfinddata_t* result)
result->size = FindFileData.nFileSizeLow;
_tcsncpy(result->name,FindFileData.cFileName,MAX_PATH);
// if no wildcard the find file handle can be closed right away
// a return value of 0 can flag this.
if (!_tcschr(dir,'*') && !_tcschr(dir,'?')) {
_findclose(hFindFile);
return 0;
}
return hFindFile;
}
@ -65,10 +43,6 @@ int _tfindnext(
{
WIN32_FIND_DATA FindFileData;
// check no wildcards or invalid handle
if (handle == 0 || handle == -1)
return 0;
if (!FindNextFile((void*)handle, &FindFileData)) {
_dosmaperr(GetLastError());
return -1;
@ -91,27 +65,11 @@ int _tfindnext(
long _tfindfirsti64(const _TCHAR *_name, struct _tfinddatai64_t *result)
{
WIN32_FIND_DATA FindFileData;
_TCHAR dir[MAX_PATH];
long hFindFile;
int len = 0;
if ( _name == NULL || _name[0] == 0 )
{
len = GetCurrentDirectory(MAX_PATH-4,dir);
if (dir[len-1] != '\\')
{
dir[len] = '\\';
dir[len+1] = 0;
}
_tcscat(dir, _T("*.*"));
}
else
_tcscpy(dir, _name);
hFindFile = (long)FindFirstFile(dir, &FindFileData);
hFindFile = (long)FindFirstFile(_name, &FindFileData);
if (hFindFile == -1)
{
memset(result,0,sizeof(struct _tfinddatai64_t));
_dosmaperr(GetLastError());
return -1;
}
@ -124,13 +82,6 @@ long _tfindfirsti64(const _TCHAR *_name, struct _tfinddatai64_t *result)
(((__int64)FindFileData.nFileSizeLow)<<32) + FindFileData.nFileSizeLow;
_tcsncpy(result->name,FindFileData.cFileName,MAX_PATH);
// if no wildcard the find file handle can be closed right away
// a return value of 0 can flag this.
if (!_tcschr(dir,'*') && !_tcschr(dir,'?')) {
_findclose(hFindFile);
return 0;
}
return hFindFile;
}
@ -145,10 +96,6 @@ int _tfindnexti64(long handle, struct _tfinddatai64_t *result)
{
WIN32_FIND_DATA FindFileData;
// check no wildcards or invalid handle
if (handle == 0 || handle == -1)
return 0;
if (!FindNextFile((HANDLE)handle, &FindFileData)) {
_dosmaperr(GetLastError());
return -1;
@ -180,10 +127,12 @@ int _findclose(
#endif
)
{
// check no wildcards or invalid handle
if (handle == 0 || handle == -1)
return 0;
return FindClose((void*)handle);
if (!FindClose((void*)handle)) {
_dosmaperr(GetLastError());
return -1;
}
return 0;
}
#endif