Send MinGW-Notify mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
https://lists.osdn.me/mailman/listinfo/mingw-notify
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of MinGW-Notify digest..."
Please do not reply to this notification; the sender address is unable to
accept incoming e-mail. If you wish to unsubscribe you can do so at
https://lists.osdn.me/mailman/listinfo/mingw-notify.
Today's Topics:
1. [mingw] #42561: MSVCRT.DLL implementation of POSIX dup2()
function does not conform to POSIX.1 (MinGW Notification List)
----------------------------------------------------------------------
Message: 1
Date: Tue, 22 Jun 2021 23:34:59 +0100
From: MinGW Notification List <[email protected]>
To: OSDN Ticket System <[email protected]>
Subject: [MinGW-Notify] [mingw] #42561: MSVCRT.DLL implementation of
POSIX dup2() function does not conform to POSIX.1
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8
#42561: MSVCRT.DLL implementation of POSIX dup2() function does not conform to
POSIX.1
Open Date: 2021-06-22 23:34
Last Update: 2021-06-22 23:34
URL for this Ticket:
https://osdn.net//projects/mingw/ticket/42561
RSS feed for this Ticket:
https://osdn.net/ticket/ticket_rss.php?group_id=3917&tid=42561
---------------------------------------------------------------------
Last Changes/Comment on this Ticket:
2021-06-22 23:34 Updated by: keith
* New Ticket "MSVCRT.DLL implementation of POSIX dup2() function does not
conform to POSIX.1" created
---------------------------------------------------------------------
Ticket Status:
Reporter: keith
Owner: (None)
Type: Issues
Status: Open
Priority: 5 - Medium
MileStone: (None)
Component: WSL
Severity: 5 - Medium
Resolution: None
---------------------------------------------------------------------
Ticket details:
I've been aware of this non-conformity for several years, yet it continues to
trip me up, on occasion. Consider the code fragment:
int fd = open( "foo.txt", O_CREAT | O_EXCL, S_IREAD | S_IWRITE ); if( dup2(
fd, STDOUT_FILENO ) != STDOUT_FILENO ) perror( "open" );On a POSIX.1
conforming platform, (with added support for the BSD standard S_IREAD and
S_IWRITE macros), assuming that "foo.txt" is successfully opened, and bound to
STDOUT_FILENO by the dup2() call, the condition dup2( fd, STDOUT_FILENO ) ==
STDOUT_FILENO will evaluate as TRUE, and the perror() call will not be invoked.
However, on Windows, the same code, (assuming that errno is zero, immediately
prior to its execution), will likely result in output (from perror(), which is
invoked) similar to:
open: Success.
The reason for this disparity, given a function prototype of int dup2( int fd1,
int fd2 ), is that, whereas POSIX.1 stipulates that the return value, following
a successful invocation, shall be equal to fd2, the Microsoft implementation
always returns zero, on success, regardless of the value of fd2.
To be fair to Microsoft, although their documentation does describe dup2() as a
POSIX function (in name only), it indicates that it is a deprecated ("because
[it doesn't] follow the Standard C rules for implementation-specific names" ...
a rationale which would seem to not be endorsed by ISO/IEC, since dup2() is
ratified as an international standard name, within ISO/IEC 9945, as it is in
IEEE 1003.1-2017) alias for Microsoft's non-standard _dup2(), for which the
documentation does indicate the non-conformity w.r.t. the return value
stipulated by POSIX.1; however, given that this catches me out, every time I
have occasion to use dup2(), and I don't think it is unreasonable to expect
POSIX.1 conformity, when I call any function by its POSIX.1 name, I really
would like to see this fixed in the MinGW implementation.
--
Ticket information of MinGW - Minimalist GNU for Windows project
MinGW - Minimalist GNU for Windows Project is hosted on OSDN
Project URL: https://osdn.net/projects/mingw/
OSDN: https://osdn.net
URL for this Ticket:
https://osdn.net/projects/mingw/ticket/42561
RSS feed for this Ticket:
https://osdn.net/ticket/ticket_rss.php?group_id=3917&tid=42561
------------------------------
Subject: Digest Footer
_______________________________________________
MinGW-Notify mailing list
[email protected]
https://lists.osdn.me/mailman/listinfo/mingw-notify
------------------------------
End of MinGW-Notify Digest, Vol 45, Issue 2
*******************************************