msvcrt: add support for _chsize_s (RETRY)

morphiend morphiend at gmail.com
Wed Aug 14 22:12:37 CDT 2013


This patch adds the _chsize_s() to the mscvrt and corresponding mscvr*s.
This was tested on Ubuntu 12.10 using IDA 6.4 as a test application.
Without the implementation of _chsize_s(), certain binaries caused an
internal crash of IDA. This patch fixed that crash.

Also, updated from the original deferred patch to add invalid parameter
invocation.

And now, fixes the commented out .spec line

---
 dlls/msvcr100/msvcr100.spec |  2 +-
 dlls/msvcr110/msvcr110.spec |  2 +-
 dlls/msvcr80/msvcr80.spec   |  2 +-
 dlls/msvcr90/msvcr90.spec   |  2 +-
 dlls/msvcrt/file.c          | 60
+++++++++++++++++++++++++++++++++++++++++++++
 dlls/msvcrt/msvcrt.spec     |  2 +-
 6 files changed, 65 insertions(+), 5 deletions(-)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.winehq.org/pipermail/wine-patches/attachments/20130814/898169f2/attachment-0001.html>
-------------- next part --------------
From 40e403d149ee164d735c58cf90a51fef53637b42 Mon Sep 17 00:00:00 2001
From: Mike Koss <morphiend at gmail.com>
Date: Wed, 14 Aug 2013 22:57:26 -0400
Subject: Added _chsize_s implementation

---
 dlls/msvcr100/msvcr100.spec |  2 +-
 dlls/msvcr110/msvcr110.spec |  2 +-
 dlls/msvcr80/msvcr80.spec   |  2 +-
 dlls/msvcr90/msvcr90.spec   |  2 +-
 dlls/msvcrt/file.c          | 60 +++++++++++++++++++++++++++++++++++++++++++++
 dlls/msvcrt/msvcrt.spec     |  2 +-
 6 files changed, 65 insertions(+), 5 deletions(-)

diff --git a/dlls/msvcr100/msvcr100.spec b/dlls/msvcr100/msvcr100.spec
index 7e602ef..73f7d1e 100644
--- a/dlls/msvcr100/msvcr100.spec
+++ b/dlls/msvcr100/msvcr100.spec
@@ -721,7 +721,7 @@
 @ cdecl -arch=i386 -norelay _chkesp() msvcrt._chkesp
 @ cdecl _chmod(str long) msvcrt._chmod
 @ cdecl _chsize(long long) msvcrt._chsize
-@ stub _chsize_s
+@ cdecl _chsize_s(long int64) msvcrt._chsize_s
 @ cdecl _clearfp() msvcrt._clearfp
 @ cdecl _close(long) msvcrt._close
 @ cdecl _commit(long) msvcrt._commit
diff --git a/dlls/msvcr110/msvcr110.spec b/dlls/msvcr110/msvcr110.spec
index 6c2da4c..4df3161 100644
--- a/dlls/msvcr110/msvcr110.spec
+++ b/dlls/msvcr110/msvcr110.spec
@@ -1073,7 +1073,7 @@
 @ cdecl -arch=i386 -norelay _chkesp() msvcrt._chkesp
 @ cdecl _chmod(str long) msvcrt._chmod
 @ cdecl _chsize(long long) msvcrt._chsize
-@ stub _chsize_s
+@ cdecl _chsize_s(long int64) msvcrt._chsize_s
 @ cdecl _clearfp() msvcrt._clearfp
 @ cdecl _close(long) msvcrt._close
 @ cdecl _commit(long) msvcrt._commit
diff --git a/dlls/msvcr80/msvcr80.spec b/dlls/msvcr80/msvcr80.spec
index ec886eb..4b07fec 100644
--- a/dlls/msvcr80/msvcr80.spec
+++ b/dlls/msvcr80/msvcr80.spec
@@ -384,7 +384,7 @@
 @ cdecl -arch=i386 -norelay _chkesp() msvcrt._chkesp
 @ cdecl _chmod(str long) msvcrt._chmod
 @ cdecl _chsize(long long) msvcrt._chsize
-@ stub _chsize_s
+@ cdecl _chsize_s(long int64) msvcrt._chsize_s
 @ cdecl _clearfp() msvcrt._clearfp
 @ cdecl _close(long) msvcrt._close
 @ cdecl _commit(long) msvcrt._commit
diff --git a/dlls/msvcr90/msvcr90.spec b/dlls/msvcr90/msvcr90.spec
index d5eebb4..9af3d1d 100644
--- a/dlls/msvcr90/msvcr90.spec
+++ b/dlls/msvcr90/msvcr90.spec
@@ -367,7 +367,7 @@
 @ cdecl -arch=i386 -norelay _chkesp() msvcrt._chkesp
 @ cdecl _chmod(str long) msvcrt._chmod
 @ cdecl _chsize(long long) msvcrt._chsize
-@ stub _chsize_s
+@ cdecl _chsize_s(long int64) msvcrt._chsize_s
 @ cdecl _clearfp() msvcrt._clearfp
 @ cdecl _close(long) msvcrt._close
 @ cdecl _commit(long) msvcrt._commit
diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c
index 8403b4b..1e6d6d5 100644
--- a/dlls/msvcrt/file.c
+++ b/dlls/msvcrt/file.c
@@ -1275,6 +1275,66 @@ int CDECL MSVCRT__chsize(int fd, MSVCRT_long size)
 }
 
 /*********************************************************************
+ *		_chsize_s (MSVCRT.@)
+ */
+int CDECL MSVCRT__chsize_s(int fd, __int64 size)
+{
+    LARGE_INTEGER cur, pos;
+    LARGE_INTEGER temp = { 0 }; 
+    HANDLE handle;
+    int ret = 0;
+
+    TRACE("(fd=%d, size=%lld)\n", fd, size);
+
+    LOCK_FILES();
+
+    handle = msvcrt_fdtoh(fd);
+    if (!MSVCRT_CHECK_PMT_ERR(handle == INVALID_HANDLE_VALUE, MSVCRT_EBADF) ||
+        !MSVCRT_CHECK_PMT_ERR(size < 0, MSVCRT_EINVAL))
+    {
+       ret = *MSVCRT__errno();
+    }
+    else
+    {
+        /* save the current file pointer */
+        if (!SetFilePointerEx(handle, temp, &cur, FILE_CURRENT))
+        {
+            msvcrt_set_errno(GetLastError());
+            ret = *MSVCRT__errno();
+        }
+        else
+        {
+            /* SetFilePointerEx uses NtSetInformationFile which
+               uses ftruncate() to extend the file size. This will
+               init bytes to 0, and thereby meet the MSDN doc for
+               _chsize_s() */
+            pos.QuadPart = size;
+            if (!SetFilePointerEx(handle, pos, &temp, FILE_BEGIN))
+            {
+                msvcrt_set_errno(GetLastError());
+                ret = *MSVCRT__errno();
+            }
+            else
+            {
+                SetEndOfFile(handle);
+                ret = SetEndOfFile(handle);
+                if (!ret)
+                {
+                    msvcrt_set_errno(GetLastError());
+                    ret = *MSVCRT__errno();
+                }
+
+               /* restore the file pointer */
+               MSVCRT__lseek(fd, cur.QuadPart, SEEK_SET);
+            }
+        }
+    }
+
+    UNLOCK_FILES();
+    return ret;
+}
+
+/*********************************************************************
  *		clearerr (MSVCRT.@)
  */
 void CDECL MSVCRT_clearerr(MSVCRT_FILE* file)
diff --git a/dlls/msvcrt/msvcrt.spec b/dlls/msvcrt/msvcrt.spec
index 7511129..a5e3ba3 100644
--- a/dlls/msvcrt/msvcrt.spec
+++ b/dlls/msvcrt/msvcrt.spec
@@ -355,7 +355,7 @@
 @ cdecl -arch=i386 -norelay _chkesp()
 @ cdecl _chmod(str long) MSVCRT__chmod
 @ cdecl _chsize(long long) MSVCRT__chsize
-# stub _chsize_s(long int64)
+@ cdecl _chsize_s(long int64) MSVCRT__chsize_s
 # stub _chvalidator(long long)
 # stub _chvalidator_l(ptr long long)
 @ cdecl _clearfp()
-- 
1.8.1.2


More information about the wine-patches mailing list