• R/O
  • HTTP
  • SSH
  • HTTPS

mingw-org-wsl: Commit

The MinGW.OSDN Windows System Libraries. Formerly designated as "MinGW.org Windows System Libraries", this encapsulates the "mingwrt" C runtime library extensions, and the "w32api" 32-bit MS-Windows API libraries.

Please note that this project no longer owns the "MinGW.org" domain name; any software which may be distributed from that domain is NOT supported by this project.


Commit MetaInfo

Revisioncf7bdc75e24a873a3dc1c1b14b8e758ddc19fc96 (tree)
Time2021-06-26 04:32:34
AuthorKeith Marshall <keith@user...>
CommiterKeith Marshall

Log Message

Correct Microsoft's dup2() POSIX.1 non-conformity.

* include/unistd.h [! defined dup2]: Define macro reference to...
(mingw_posix_dup2): ...this new in-line function, (as named by the
macro); it overrides the Microsoft dup2() function, to ensure that it
returns the correct file descriptor, as specified by POSIX.1, rather
than zero, as returned by the Microsoft implementation, on success.

Change Summary

Incremental Difference

--- a/mingwrt/ChangeLog
+++ b/mingwrt/ChangeLog
@@ -1,3 +1,13 @@
1+2021-06-25 Keith Marshall <keith@users.osdn.me>
2+
3+ Correct Microsoft's dup2() POSIX.1 non-conformity.
4+
5+ * include/unistd.h [! defined dup2]: Define macro reference to...
6+ (__mingw_posix_dup2): ...this new in-line function, (as named by the
7+ macro); it overrides the Microsoft dup2() function, to ensure that it
8+ returns the correct file descriptor, as specified by POSIX.1, rather
9+ than zero, as returned by the Microsoft implementation, on success.
10+
111 2021-06-13 Keith Marshall <keith@users.osdn.me>
212
313 Implement a POSIX.1 compliant pseudo-random number generator.
--- a/mingwrt/include/unistd.h
+++ b/mingwrt/include/unistd.h
@@ -10,9 +10,9 @@
1010 * Danny Smith <dannysmith@users.sourceforge.net>
1111 * Ramiro Polla <ramiro@lisha.ufsc.br>
1212 * Gregory McGarry <gregorymcgarry@users.sourceforge.net>
13- * Keith Marshall <keithmarshall@users.sourceforge.net>
13+ * Keith Marshall <keith@users.osdn.me>
1414 * Copyright (C) 1997, 1999, 2002-2004, 2007-2009, 2014-2017, 2020,
15- * MinGW.org Project.
15+ * 2021, MinGW.org Project.
1616 *
1717 *
1818 * Permission is hereby granted, free of charge, to any person obtaining a
@@ -127,6 +127,23 @@ unsigned sleep( unsigned period ){ return __mingw_sleep( period, 0 ); }
127127 */
128128 int __cdecl ftruncate( int, off_t );
129129
130+#ifndef dup2
131+/* Microsoft's implementation of dup2(), (which is documented as being a
132+ * POSIX.1 function), does NOT actually conform to POSIX.1 behaviour; (on
133+ * success, it returns zero, but POSIX.1 specifies that it should return
134+ * the file descriptor to which assignment has been forced). To be fair
135+ * to Microsoft, the anomalous behaviour is as they document it; however,
136+ * it may seem reasonable for the user to expect conformity with POSIX.1,
137+ * particularly when <unistd.h> has been included. Unless the user has
138+ * provided a prior definition for dup2(), this in-line implementation
139+ * will deliver such conformity.
140+ */
141+#define dup2 __mingw_posix_dup2
142+__CRT_ALIAS __LIBIMPL__(( FUNCTION = dup2 ))
143+__cdecl __MINGW_NOTHROW int dup2 (int __fd1, int __fd2)
144+{ return ((__fd1 = _dup2( __fd1, __fd2 )) == 0) ? __fd2 : __fd1; }
145+#endif /* ! defined dup2 */
146+
130147 #ifndef __NO_INLINE__
131148 __CRT_INLINE __JMPSTUB__(( FUNCTION = ftruncate, DLLENTRY = _chsize ))
132149 int ftruncate( int __fd, off_t __length ){ return _chsize( __fd, __length ); }
Show on old repository browser