Re: RFC: Work around POSIX non-conformity of Microsoft's dup2() function

Keith Marshall <[email protected]> Sat, 26 Jun 2021 22:07:10 +0100
Newsgroups gmane.comp.gnu.mingw.user
Organization MinGW.org Project
Message-ID <[email protected]>
This is an OpenPGP/MIME signed message (RFC 4880 and 3156)
--===============5325939189636021147==
Content-Type: multipart/signed; micalg=pgp-sha256;
 protocol="application/pgp-signature";
 boundary="FlMBTvOxH6qqOQHVWCMv36OYxlagORkf2"

This is an OpenPGP/MIME signed message (RFC 4880 and 3156)
--FlMBTvOxH6qqOQHVWCMv36OYxlagORkf2
Content-Type: multipart/mixed; boundary="VBlfEbSEWcZYPSpNJzBxpflnzjwRDP1Ey";
 protected-headers="v1"
From: Keith Marshall <[email protected]>
Reply-To: keith.d.marshall-XZoyATsUNX5Wk0Htik3J/[email protected]
To: [email protected]
Message-ID: <cd43e8ab-a921-d39d-b988-a2f7638d5d5c-JlWs9+JhQMeJPt80KsDg5Q@public.gmane.org>
Subject: Re: [MinGW-Users] RFC: Work around POSIX non-conformity of
 Microsoft's dup2() function
References: <927e5be5-e2b1-4970-3b14-b6ab9d3a0db8-JlWs9+JhQMeJPt80KsDg5Q@public.gmane.org>
 <107ad3cb-eea6-0474-8176-bd24f881c11f-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
In-Reply-To: <107ad3cb-eea6-0474-8176-bd24f881c11f-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

--VBlfEbSEWcZYPSpNJzBxpflnzjwRDP1Ey
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: quoted-printable

On 26/06/2021 18:22, Manolo wrote:
> El 25/06/2021 a las 20:36, Keith Marshall escribi=C3=B3:
>> 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 actio=
n,
>> as ticket https://osdn.net/projects/mingw/ticket/42561
>=20
> [...snip...]
>=20
> If I code for Windows I expect my app to behave as if I have compiled i=
t
> 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

--=20
Regards,
Keith.

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


--VBlfEbSEWcZYPSpNJzBxpflnzjwRDP1Ey--

--FlMBTvOxH6qqOQHVWCMv36OYxlagORkf2
Content-Type: application/pgp-signature; name="OpenPGP_signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="OpenPGP_signature"

-----BEGIN PGP SIGNATURE-----

wsF5BAABCAAjFiEEwZ7AGBVH3lDh1I9TwK02xjR+Wj8FAmDXlv4FAwAAAAAACgkQwK02xjR+Wj+p
Uw//aoNApA8SsjG0sQMZX94WTD7KZmcfaaqbT0IvR63Ekxc5/9tJseofTgUzv0g/L+SPBAxycZFn
gAsW2R5sIo+CZHPdcBsxC1fFLKqkjbNnPsjwN5U42rwlRnRT1hG6tjrBCK4ymw2uZD7SH+pT3tom
jthSLk7h+TNRxGnQ7IT9ZC4JvD1jklDXlr6/J9F5PT/MYggsnC9R6dIfNzhz/PUmgAmy8uEbYRTO
6KRCEc2JaE5PTqH+E7U1iHr16BUjs1Dk+tlElSuA46Q+BLzgfYHyYiSKpyI9feOIIvYQy03ppMBf
SGJIYG/qk1xPKcpRjkb9lYgDKTNnyocV/mudQHByM/YIEqqAHWNdtn7EuE44vx0IJJmNtzk1OK/B
sVOK27nYAfFLdvHmWXN80lsA4dZ05Y2gF/Us6tC6aMC5xsQ1dJfZ04T5UBuiLrFNTPuHEH1aZAl9
GpqTg6ialfdd+Rs9mZD5OddazBQL/VLfMavcuepBJldFfKDega53l/1538Oq3sL/js6sEpTSS3Ta
tWxjEUPUVs9gRtEnrrkbV2LdzDJwGLcEdKbPsJgo3TJmcnzI4nlFYCroUnk32mTq9cc2/0MnYhf6
CaqN7IlYwcr1HIjRXAvYXnErgzYJeKZjzz8+2VI9XqVCTI4H0urukDcBzKBt+vl5i/zCG3Kfr17s
/u4=
=Ss2M
-----END PGP SIGNATURE-----

--FlMBTvOxH6qqOQHVWCMv36OYxlagORkf2--


--===============5325939189636021147==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: inline

X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KTWluR1ctVXNl
cnMgbWFpbGluZyBsaXN0Ck1pbkdXLVVzZXJzQGxpc3RzLm9zZG4ubWUKClRoaXMgbGlzdCBvYnNl
cnZlcyB0aGUgUG9zdGluZyBFdGlxdWV0dGUsIGFzIGRlc2NyaWJlZCBhdCBodHRwczovL21pbmd3
Lm9zZG4uaW8vaW5kZXguaHRtbD9wYWdlPW1haWxpbmcuaHRtbCNsaXN0LWV0aXF1ZXR0ZS4KV2Ug
YXNrIHRoYXQgeW91IGJlIHBvbGl0ZSBhbmQgZG8gdGhlIHNhbWUuICBEaXNyZWdhcmQgZm9yIHRo
ZSBsaXN0IGV0aXF1ZXR0ZSBtYXkgY2F1c2UgeW91ciBhY2NvdW50IHRvIGJlIG1vZGVyYXRlZC4K
Cl9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fCllvdSBtYXkg
Y2hhbmdlIHlvdXIgTWluR1cgQWNjb3VudCBPcHRpb25zIG9yIHVuc3Vic2NyaWJlIGF0OgpodHRw
czovL2xpc3RzLm9zZG4ubWUvbWFpbG1hbi9saXN0aW5mby9taW5ndy11c2VycwpBbHNvOiBtYWls
dG86bWluZ3ctdXNlcnMtcmVxdWVzdEBsaXN0cy5vc2RuLm1lP3N1YmplY3Q9dW5zdWJzY3JpYmU=

--===============5325939189636021147==--