mirror of
https://github.com/reactos/reactos.git
synced 2025-07-31 11:31:40 +00:00
[CRT] Update file descriptor handling to match Wine (3/7). CORE-14504
Import Wine commits by Piotr Caban: * 6c2d4f1092d msvcrt: Use fd critical section in _fstat64. * 9278190d468 msvcrt: Use fd critical section in _futime64.
This commit is contained in:
parent
9eb1eae28c
commit
c529e727d7
4 changed files with 35 additions and 23 deletions
|
@ -1,8 +1,10 @@
|
|||
#include <precomp.h>
|
||||
#include <tchar.h>
|
||||
#include <direct.h>
|
||||
#include <internal/wine/msvcrt.h>
|
||||
|
||||
HANDLE fdtoh(int fd);
|
||||
inline ioinfo* get_ioinfo(int fd);
|
||||
inline void release_ioinfo(ioinfo *info);
|
||||
|
||||
#define ALL_S_IREAD (_S_IREAD | (_S_IREAD >> 3) | (_S_IREAD >> 6))
|
||||
#define ALL_S_IWRITE (_S_IWRITE | (_S_IWRITE >> 3) | (_S_IWRITE >> 6))
|
||||
|
@ -97,25 +99,29 @@ int CDECL _tstat64(const _TCHAR *path, struct __stat64 *buf)
|
|||
|
||||
int CDECL _fstat64(int fd, struct __stat64* buf)
|
||||
{
|
||||
ioinfo *info = get_ioinfo(fd);
|
||||
DWORD dw;
|
||||
DWORD type;
|
||||
BY_HANDLE_FILE_INFORMATION hfi;
|
||||
HANDLE hand = fdtoh(fd);
|
||||
|
||||
TRACE(":fd (%d) stat (%p)\n",fd,buf);
|
||||
if (hand == INVALID_HANDLE_VALUE)
|
||||
TRACE(":fd (%d) stat (%p)\n", fd, buf);
|
||||
if (info->handle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
release_ioinfo(info);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!buf)
|
||||
{
|
||||
WARN(":failed-NULL buf\n");
|
||||
_dosmaperr(ERROR_INVALID_PARAMETER);
|
||||
release_ioinfo(info);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&hfi, 0, sizeof(hfi));
|
||||
memset(buf, 0, sizeof(struct __stat64));
|
||||
type = GetFileType(hand);
|
||||
type = GetFileType(info->handle);
|
||||
if (type == FILE_TYPE_PIPE)
|
||||
{
|
||||
buf->st_dev = buf->st_rdev = fd;
|
||||
|
@ -130,10 +136,11 @@ int CDECL _fstat64(int fd, struct __stat64* buf)
|
|||
}
|
||||
else /* FILE_TYPE_DISK etc. */
|
||||
{
|
||||
if (!GetFileInformationByHandle(hand, &hfi))
|
||||
if (!GetFileInformationByHandle(info->handle, &hfi))
|
||||
{
|
||||
WARN(":failed-last error (%d)\n",GetLastError());
|
||||
_dosmaperr(ERROR_INVALID_PARAMETER);
|
||||
release_ioinfo(info);
|
||||
return -1;
|
||||
}
|
||||
buf->st_mode = _S_IFREG | ALL_S_IREAD;
|
||||
|
@ -148,6 +155,7 @@ int CDECL _fstat64(int fd, struct __stat64* buf)
|
|||
}
|
||||
TRACE(":dwFileAttributes = 0x%x, mode set to 0x%x\n",hfi.dwFileAttributes,
|
||||
buf->st_mode);
|
||||
release_ioinfo(info);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue