msvcrt-A10: _dup2

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch in the msvcrt-A?? series implements the _dup2 function which 
allows for the duplication of a file descriptor into another one.

License:
LGPL

Changelog:
* dlls/msvcrt/file.c, dlls/msvcrt/msvcrt.spec: Jaco Greeff <jaco@puxedo.org>
- Implement the _dup2 function to duplicate a file descriptor into 
another one

--[ inline patch ]--

diff -aurN msvcrt-A09/dlls/msvcrt/file.c msvcrt-A10/dlls/msvcrt/file.c
--- msvcrt-A09/dlls/msvcrt/file.c	Mon Nov  4 14:07:29 2002
+++ msvcrt-A10/dlls/msvcrt/file.c	Mon Nov  4 14:34:28 2002
@@ -718,6 +718,46 @@
  }

  /*********************************************************************
+ *      _dup2 (MSVCRT.@)
+ */
+int _dup2(int fd1, int fd2)
+{
+    HANDLE hand = msvcrt_fdtoh(fd1);
+
+    TRACE("(fd1 == %d, fd2 == %d)\n", fd1, fd2);
+
+    /* Make sure that the handle for fd1 is valid and
+     * that fd2 is a valid file descriptor
+     */
+    if (hand == INVALID_HANDLE_VALUE)
+    {
+        TRACE("Invalid fd == %d, no associated handle\n", fd1);
+        return -1;
+    }
+    else if ((fd2 < 0) || (fd2 >= MSVCRT_fdend))
+    {
+        TRACE("Invalid fd == %d\n", fd2);
+        return -1;
+    }
+
+    /* Close the file associated with fd2, before
+     * assigning it another value from fd1
+     */
+    _close(fd2);
+
+    /* Duplicate the file handle and flags for fd2,
+     * to allow us to have access to the same file as
+     * per the original fd1
+     */
+    MSVCRT_handles[fd2] = MSVCRT_handles[fd1];
+    MSVCRT_flags[fd2] = MSVCRT_flags[fd1];
+    MSVCRT_files[fd2] = NULL;
+    MSVCRT_tempfiles[fd2] = NULL;
+
+    return 0;
+}
+
+/*********************************************************************
   *		_wfdopen (MSVCRT.@)
   */
  MSVCRT_FILE* _wfdopen(int fd, const WCHAR *mode)
diff -aurN msvcrt-A09/dlls/msvcrt/msvcrt.spec 
msvcrt-A10/dlls/msvcrt/msvcrt.spec
--- msvcrt-A09/dlls/msvcrt/msvcrt.spec	Mon Nov  4 14:06:43 2002
+++ msvcrt-A10/dlls/msvcrt/msvcrt.spec	Mon Nov  4 14:22:34 2002
@@ -197,7 +197,7 @@
  @ stub _daylight
  @ stub _dstbias
  @ cdecl _dup(long) _dup
-@ stub _dup2 #(long long)
+@ cdecl _dup2(long long) _dup2
  @ cdecl _ecvt( double long ptr ptr) ecvt
  @ cdecl _endthread () _endthread
  @ cdecl _endthreadex(long) _endthreadex



[Index of Archives]     [Gimp for Windows]     [Red Hat]     [Samba]     [Yosemite Camping]     [Graphics Cards]     [Wine Home]

  Powered by Linux