mirror of
https://github.com/reactos/reactos.git
synced 2024-12-26 17:14:41 +00:00
Rewrote _stat functions. This functions can't use _fstat.
svn path=/trunk/; revision=3366
This commit is contained in:
parent
82557ffc26
commit
0127899031
1 changed files with 159 additions and 21 deletions
|
@ -2,51 +2,189 @@
|
|||
#include <msvcrt/sys/stat.h>
|
||||
#include <msvcrt/fcntl.h>
|
||||
#include <msvcrt/io.h>
|
||||
#include <msvcrt/errno.h>
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
int _stat(const char *path, struct stat *buffer)
|
||||
{
|
||||
int fd = _open(path,_O_RDONLY);
|
||||
int ret;
|
||||
HANDLE findHandle;
|
||||
WIN32_FIND_DATAA findData;
|
||||
|
||||
if (fd < 0)
|
||||
if (!buffer)
|
||||
{
|
||||
__set_errno(EINVAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = fstat(fd,buffer);
|
||||
_close(fd);
|
||||
if(strchr(path, '*') || strchr(path, '?'))
|
||||
{
|
||||
__set_errno(EINVAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
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 = 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))
|
||||
buffer->st_mode |= S_IWRITE;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
__int64 _stati64 (const char *path, struct _stati64 *buffer)
|
||||
{
|
||||
int fd = _open(path,_O_RDONLY);
|
||||
int ret;
|
||||
HANDLE findHandle;
|
||||
WIN32_FIND_DATAA findData;
|
||||
|
||||
ret = _fstati64(fd,buffer);
|
||||
_close(fd);
|
||||
if (!buffer)
|
||||
{
|
||||
__set_errno(EINVAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
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))
|
||||
buffer->st_mode |= S_IWRITE;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wstat (const wchar_t *path, struct stat *buffer)
|
||||
{
|
||||
int fd = _wopen(path,_O_RDONLY);
|
||||
int ret;
|
||||
HANDLE findHandle;
|
||||
WIN32_FIND_DATAW findData;
|
||||
|
||||
ret = fstat(fd,buffer);
|
||||
_close(fd);
|
||||
if (!buffer)
|
||||
{
|
||||
__set_errno(EINVAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
if(wcschr(path, L'*') || wcschr(path, L'?'))
|
||||
{
|
||||
__set_errno(EINVAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
findHandle = FindFirstFileW(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 = 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))
|
||||
buffer->st_mode |= S_IWRITE;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
__int64 _wstati64 (const wchar_t *path, struct _stati64 *buffer)
|
||||
{
|
||||
int fd = _wopen(path,_O_RDONLY);
|
||||
int ret;
|
||||
HANDLE findHandle;
|
||||
WIN32_FIND_DATAW findData;
|
||||
|
||||
ret = _fstati64(fd,buffer);
|
||||
_close(fd);
|
||||
if (!buffer)
|
||||
{
|
||||
__set_errno(EINVAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
if(wcschr(path, L'*') || wcschr(path, L'?'))
|
||||
{
|
||||
__set_errno(EINVAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
findHandle = FindFirstFileW(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))
|
||||
buffer->st_mode |= S_IWRITE;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue