Commit f2f45d5f authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

msvcrt: Use fd critical section in _chsize_s.

parent fa6de597
...@@ -1377,18 +1377,17 @@ int CDECL MSVCRT__fseek_nolock(MSVCRT_FILE* file, MSVCRT_long offset, int whence ...@@ -1377,18 +1377,17 @@ int CDECL MSVCRT__fseek_nolock(MSVCRT_FILE* file, MSVCRT_long offset, int whence
*/ */
int CDECL MSVCRT__chsize_s(int fd, __int64 size) int CDECL MSVCRT__chsize_s(int fd, __int64 size)
{ {
ioinfo *info;
__int64 cur, pos; __int64 cur, pos;
HANDLE handle;
BOOL ret = FALSE; BOOL ret = FALSE;
TRACE("(fd=%d, size=%s)\n", fd, wine_dbgstr_longlong(size)); TRACE("(fd=%d, size=%s)\n", fd, wine_dbgstr_longlong(size));
if (!MSVCRT_CHECK_PMT(size >= 0)) return MSVCRT_EINVAL; if (!MSVCRT_CHECK_PMT(size >= 0)) return MSVCRT_EINVAL;
LOCK_FILES();
handle = msvcrt_fdtoh(fd); info = get_ioinfo(fd);
if (handle != INVALID_HANDLE_VALUE) if (info->handle != INVALID_HANDLE_VALUE)
{ {
/* save the current file pointer */ /* save the current file pointer */
cur = MSVCRT__lseeki64(fd, 0, SEEK_CUR); cur = MSVCRT__lseeki64(fd, 0, SEEK_CUR);
...@@ -1397,7 +1396,7 @@ int CDECL MSVCRT__chsize_s(int fd, __int64 size) ...@@ -1397,7 +1396,7 @@ int CDECL MSVCRT__chsize_s(int fd, __int64 size)
pos = MSVCRT__lseeki64(fd, size, SEEK_SET); pos = MSVCRT__lseeki64(fd, size, SEEK_SET);
if (pos >= 0) if (pos >= 0)
{ {
ret = SetEndOfFile(handle); ret = SetEndOfFile(info->handle);
if (!ret) msvcrt_set_errno(GetLastError()); if (!ret) msvcrt_set_errno(GetLastError());
} }
...@@ -1406,7 +1405,7 @@ int CDECL MSVCRT__chsize_s(int fd, __int64 size) ...@@ -1406,7 +1405,7 @@ int CDECL MSVCRT__chsize_s(int fd, __int64 size)
} }
} }
UNLOCK_FILES(); release_ioinfo(info);
return ret ? 0 : *MSVCRT__errno(); return ret ? 0 : *MSVCRT__errno();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment