[MinGW-Users] RFC: Work around POSIX non-conformity of Microsoft's dup2() function

Back to archive index
Keith Marshall keith****@users*****
Sun Jun 27 06:07:10 JST 2021


On 26/06/2021 18:22, Manolo wrote:
> El 25/06/2021 a las 20:36, Keith Marshall escribió:
>> The documentation describes it as a POSIX function, (in name at least,
>> and albeit deprecated for use with MSVC), but its behaviour definitely
>> does NOT conform to the POSIX.1 specification.
>>
>> I've written a description of the issue, and proposed corrective action,
>> as ticket https://osdn.net/projects/mingw/ticket/42561
> 
> [...snip...]
> 
> If I code for Windows I expect my app to behave as if I have compiled it
> only with MS tools (VC++, etc). If I have a doubt about some command I
> usually search for info at MSDN.

Okay.  If you've followed the discussion on the ticket, you may observe
that my preferred work-around will be activated only if <unistd.h> has
been included.  If you are coding for Microsoft tools, (and Visual C++
in particular), you are unlikely to include that, because Microsoft's
closest equivalent is <io.h>.  Even if you do include some 3rd party
<unistd.h>, it probably will not include the proposed MinGW work-around,
so in either case, Microsoft's behaviour will be preserved.  If you did
happen to include MinGW's <unistd.h>, with the work-around, you could
still disable its effect, by adding:

   #define dup2 dup2

*before* you include <unistd.h>, and again, Microsoft's behaviour would
be preserved.

> If I code for multiplatform I expect the same behaviour in all OS's. In
> case of searching for info, I prefer GNU docs.

That may be ill advised: GNU libraries are littered with non-standard,
documented embellishments; if you make use of any of them, that could
seriously impair portability.  My own preference, when coding with
portability in mind, is to consult the online POSIX specification:

   http://pubs.opengroup.org/onlinepubs/9699919799/nframe.html

-- 
Regards,
Keith.

Public key available from keys.gnupg.net
Key fingerprint: C19E C018 1547 DE50 E1D4 8F53 C0AD 36C6 347E 5A3F

-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: <https://lists.osdn.me/mailman/archives/mingw-users/attachments/20210626/891d1556/attachment.sig>


More information about the MinGW-Users mailing list
Back to archive index