mirror of
https://github.com/reactos/reactos.git
synced 2025-02-24 17:34:57 +00:00
- Replaced FindFirstFile/FindClose with GetFileAttributesEx.
- Fixed some minor bugs. svn path=/trunk/; revision=4879
This commit is contained in:
parent
48be1aeb7d
commit
a3048f0254
2 changed files with 101 additions and 89 deletions
|
@ -10,8 +10,7 @@
|
|||
|
||||
int _stat(const char* path, struct stat* buffer)
|
||||
{
|
||||
HANDLE findHandle;
|
||||
WIN32_FIND_DATAA findData;
|
||||
WIN32_FILE_ATTRIBUTE_DATA fileAttributeData;
|
||||
char* ext;
|
||||
|
||||
if (!buffer)
|
||||
|
@ -26,38 +25,87 @@ int _stat(const char* path, struct stat* buffer)
|
|||
return -1;
|
||||
}
|
||||
|
||||
findHandle = FindFirstFileA(path, &findData);
|
||||
if (findHandle == INVALID_HANDLE_VALUE)
|
||||
if (!GetFileAttributesExA(path, GetFileExInfoStandard, &fileAttributeData))
|
||||
{
|
||||
__set_errno(ENOENT);
|
||||
return -1;
|
||||
}
|
||||
|
||||
FindClose(findHandle);
|
||||
|
||||
memset (buffer, 0, sizeof(struct stat));
|
||||
|
||||
buffer->st_ctime = FileTimeToUnixTime(&findData.ftCreationTime,NULL);
|
||||
buffer->st_atime = FileTimeToUnixTime(&findData.ftLastAccessTime,NULL);
|
||||
buffer->st_mtime = FileTimeToUnixTime(&findData.ftLastWriteTime,NULL);
|
||||
buffer->st_ctime = FileTimeToUnixTime(&fileAttributeData.ftCreationTime,NULL);
|
||||
buffer->st_atime = FileTimeToUnixTime(&fileAttributeData.ftLastAccessTime,NULL);
|
||||
buffer->st_mtime = FileTimeToUnixTime(&fileAttributeData.ftLastWriteTime,NULL);
|
||||
|
||||
// statbuf->st_dev = fd;
|
||||
buffer->st_size = findData.nFileSizeLow;
|
||||
buffer->st_size = fileAttributeData.nFileSizeLow;
|
||||
buffer->st_mode = S_IREAD;
|
||||
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||
if (fileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||
buffer->st_mode |= S_IFDIR;
|
||||
else
|
||||
{
|
||||
buffer->st_mode |= S_IFREG;
|
||||
ext = strrchr(path, '.');
|
||||
if (ext && (!stricmp(ext, ".exe") ||
|
||||
!stricmp(ext, ".com") ||
|
||||
!stricmp(ext, ".bat") ||
|
||||
!stricmp(ext, ".cmd")))
|
||||
if (ext && (!_stricmp(ext, ".exe") ||
|
||||
!_stricmp(ext, ".com") ||
|
||||
!_stricmp(ext, ".bat") ||
|
||||
!_stricmp(ext, ".cmd")))
|
||||
buffer->st_mode |= S_IEXEC;
|
||||
}
|
||||
if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
|
||||
if (!(fileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
|
||||
buffer->st_mode |= S_IWRITE;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
__int64 _stati64 (const char *path, struct _stati64 *buffer)
|
||||
{
|
||||
WIN32_FILE_ATTRIBUTE_DATA fileAttributeData;
|
||||
char* ext;
|
||||
|
||||
if (!buffer)
|
||||
{
|
||||
__set_errno(EINVAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(strchr(path, '*') || strchr(path, '?'))
|
||||
{
|
||||
__set_errno(ENOENT);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!GetFileAttributesExA(path, GetFileExInfoStandard, &fileAttributeData))
|
||||
{
|
||||
__set_errno(ENOENT);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset (buffer, 0, sizeof(struct _stati64));
|
||||
|
||||
buffer->st_ctime = FileTimeToUnixTime(&fileAttributeData.ftCreationTime,NULL);
|
||||
buffer->st_atime = FileTimeToUnixTime(&fileAttributeData.ftLastAccessTime,NULL);
|
||||
buffer->st_mtime = FileTimeToUnixTime(&fileAttributeData.ftLastWriteTime,NULL);
|
||||
|
||||
// statbuf->st_dev = fd;
|
||||
buffer->st_size = ((((__int64)fileAttributeData.nFileSizeHigh) << 16) << 16) +
|
||||
fileAttributeData.nFileSizeLow;
|
||||
buffer->st_mode = S_IREAD;
|
||||
if (fileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||
buffer->st_mode |= S_IFDIR;
|
||||
else
|
||||
{
|
||||
buffer->st_mode |= S_IFREG;
|
||||
ext = strrchr(path, '.');
|
||||
if (ext && (!_stricmp(ext, ".exe") ||
|
||||
!_stricmp(ext, ".com") ||
|
||||
!_stricmp(ext, ".bat") ||
|
||||
!_stricmp(ext, ".cmd")))
|
||||
buffer->st_mode |= S_IEXEC;
|
||||
}
|
||||
if (!(fileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
|
||||
buffer->st_mode |= S_IWRITE;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,8 +10,8 @@
|
|||
|
||||
int _wstat (const wchar_t *path, struct stat *buffer)
|
||||
{
|
||||
HANDLE findHandle;
|
||||
WIN32_FIND_DATAW findData;
|
||||
WIN32_FILE_ATTRIBUTE_DATA fileAttributeData;
|
||||
wchar_t ext;
|
||||
|
||||
if (!buffer)
|
||||
{
|
||||
|
@ -21,79 +21,38 @@ int _wstat (const wchar_t *path, struct stat *buffer)
|
|||
|
||||
if(wcschr(path, L'*') || wcschr(path, L'?'))
|
||||
{
|
||||
__set_errno(EINVAL);
|
||||
__set_errno(ENOENT);
|
||||
return -1;
|
||||
}
|
||||
|
||||
findHandle = FindFirstFileW(path, &findData);
|
||||
if (findHandle == INVALID_HANDLE_VALUE)
|
||||
if (!GetFileAttributesExW(path, GetFileExInfoStandard, &fileAttributeData))
|
||||
{
|
||||
__set_errno(ENOENT);
|
||||
return -1;
|
||||
}
|
||||
|
||||
FindClose(findHandle);
|
||||
|
||||
memset (buffer, 0, sizeof(struct stat));
|
||||
|
||||
buffer->st_ctime = FileTimeToUnixTime(&findData.ftCreationTime,NULL);
|
||||
buffer->st_atime = FileTimeToUnixTime(&findData.ftLastAccessTime,NULL);
|
||||
buffer->st_mtime = FileTimeToUnixTime(&findData.ftLastWriteTime,NULL);
|
||||
buffer->st_ctime = FileTimeToUnixTime(&fileAttributeData.ftCreationTime,NULL);
|
||||
buffer->st_atime = FileTimeToUnixTime(&fileAttributeData.ftLastAccessTime,NULL);
|
||||
buffer->st_mtime = FileTimeToUnixTime(&fileAttributeData.ftLastWriteTime,NULL);
|
||||
|
||||
// statbuf->st_dev = fd;
|
||||
buffer->st_size = findData.nFileSizeLow;
|
||||
buffer->st_size = fileAttributeData.nFileSizeLow;
|
||||
buffer->st_mode = S_IREAD;
|
||||
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||
if (fileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||
buffer->st_mode |= S_IFDIR;
|
||||
else
|
||||
{
|
||||
buffer->st_mode |= S_IFREG;
|
||||
if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
|
||||
buffer->st_mode |= S_IWRITE;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
__int64 _stati64 (const char *path, struct _stati64 *buffer)
|
||||
{
|
||||
HANDLE findHandle;
|
||||
WIN32_FIND_DATAA findData;
|
||||
|
||||
if (!buffer)
|
||||
{
|
||||
__set_errno(EINVAL);
|
||||
return -1;
|
||||
ext = wcsrchr(path, L'.');
|
||||
if (ext && (!_wcsicmp(ext, L".exe") ||
|
||||
!_wcsicmp(ext, L".com") ||
|
||||
!_wcsicmp(ext, L".bat") ||
|
||||
!_wcsicmp(ext, L".cmd")))
|
||||
buffer->st_mode |= S_IEXEC;
|
||||
}
|
||||
|
||||
if(strchr(path, '*') || strchr(path, '?'))
|
||||
{
|
||||
__set_errno(EINVAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
findHandle = FindFirstFileA(path, &findData);
|
||||
if (findHandle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
__set_errno(ENOENT);
|
||||
return -1;
|
||||
}
|
||||
|
||||
FindClose(findHandle);
|
||||
|
||||
memset (buffer, 0, sizeof(struct stat));
|
||||
|
||||
buffer->st_ctime = FileTimeToUnixTime(&findData.ftCreationTime,NULL);
|
||||
buffer->st_atime = FileTimeToUnixTime(&findData.ftLastAccessTime,NULL);
|
||||
buffer->st_mtime = FileTimeToUnixTime(&findData.ftLastWriteTime,NULL);
|
||||
|
||||
// statbuf->st_dev = fd;
|
||||
buffer->st_size = (((__int64)findData.nFileSizeHigh) << 32) +
|
||||
findData.nFileSizeLow;
|
||||
buffer->st_mode = S_IREAD;
|
||||
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||
buffer->st_mode |= S_IFDIR;
|
||||
else
|
||||
buffer->st_mode |= S_IFREG;
|
||||
if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
|
||||
if (!(fileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
|
||||
buffer->st_mode |= S_IWRITE;
|
||||
|
||||
return 0;
|
||||
|
@ -101,8 +60,8 @@ __int64 _stati64 (const char *path, struct _stati64 *buffer)
|
|||
|
||||
__int64 _wstati64 (const wchar_t *path, struct _stati64 *buffer)
|
||||
{
|
||||
HANDLE findHandle;
|
||||
WIN32_FIND_DATAW findData;
|
||||
WIN32_FILE_ATTRIBUTE_DATA fileAttributeData;
|
||||
wchar_t ext;
|
||||
|
||||
if (!buffer)
|
||||
{
|
||||
|
@ -112,34 +71,39 @@ __int64 _wstati64 (const wchar_t *path, struct _stati64 *buffer)
|
|||
|
||||
if(wcschr(path, L'*') || wcschr(path, L'?'))
|
||||
{
|
||||
__set_errno(EINVAL);
|
||||
__set_errno(ENOENT);
|
||||
return -1;
|
||||
}
|
||||
|
||||
findHandle = FindFirstFileW(path, &findData);
|
||||
if (findHandle == INVALID_HANDLE_VALUE)
|
||||
if (!GetFileAttributesExW(path, GetFileExInfoStandard, &fileAttributeData))
|
||||
{
|
||||
__set_errno(ENOENT);
|
||||
return -1;
|
||||
}
|
||||
|
||||
FindClose(findHandle);
|
||||
memset (buffer, 0, sizeof(struct _stati64));
|
||||
|
||||
memset (buffer, 0, sizeof(struct stat));
|
||||
|
||||
buffer->st_ctime = FileTimeToUnixTime(&findData.ftCreationTime,NULL);
|
||||
buffer->st_atime = FileTimeToUnixTime(&findData.ftLastAccessTime,NULL);
|
||||
buffer->st_mtime = FileTimeToUnixTime(&findData.ftLastWriteTime,NULL);
|
||||
buffer->st_ctime = FileTimeToUnixTime(&fileAttributeData.ftCreationTime,NULL);
|
||||
buffer->st_atime = FileTimeToUnixTime(&fileAttributeData.ftLastAccessTime,NULL);
|
||||
buffer->st_mtime = FileTimeToUnixTime(&fileAttributeData.ftLastWriteTime,NULL);
|
||||
|
||||
// statbuf->st_dev = fd;
|
||||
buffer->st_size = (((__int64)findData.nFileSizeHigh) << 32) +
|
||||
findData.nFileSizeLow;
|
||||
buffer->st_size = ((((__int64)fileAttributeData.nFileSizeHigh) << 16) << 16) +
|
||||
fileAttributeData.nFileSizeLow;
|
||||
buffer->st_mode = S_IREAD;
|
||||
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||
if (fileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||
buffer->st_mode |= S_IFDIR;
|
||||
else
|
||||
{
|
||||
buffer->st_mode |= S_IFREG;
|
||||
if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
|
||||
ext = wcsrchr(path, L'.');
|
||||
if (ext && (!_wcsicmp(ext, L".exe") ||
|
||||
!_wcsicmp(ext, L".com") ||
|
||||
!_wcsicmp(ext, L".bat") ||
|
||||
!_wcsicmp(ext, L".cmd")))
|
||||
buffer->st_mode |= S_IEXEC;
|
||||
}
|
||||
if (!(fileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
|
||||
buffer->st_mode |= S_IWRITE;
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Reference in a new issue