Re: [PATCH] vasnprintf: fix potential use after free
On 08/12/14 02:29, Paul Eggert wrote: Pádraig Brady wrote: BTW if free() may reset errno on some platforms then it's probably worth augmenting the gnulib free() wrapper to restore errno if needed, The documented GNU behavior for 'free' allows 'free' to set errno, right? So why should the corresponding gnulib wrapper guarantee behavior above and beyond what GNU implements? It might make sense to have a variant of 'free' that preserves errno, but we should probably give the variant a different name. 'noerr_free', say. Well gnu docs never mention errno wrt free() so I suppose it's therefore possible to be set to anything. I did check GNU,{free,net,open}bsd,solaris and none touch the errno for valid, NULL, or invalid pointers. However I suppose there are certain edge cases where the errno can be set. For example see the discussion at: http://lists.freebsd.org/pipermail/freebsd-arch/2012-June/012669.html Moreover since it's not practical to test for those cases at configure time, the POSIX note previously referenced in this thread is not possible to take advantage of portably. Hence I pushed the attached to address this. thanks, Pádraig. From ec6a60bfd9ba0f12ec07809636891909ee7ded66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= p...@draigbrady.com Date: Mon, 8 Dec 2014 09:46:38 + Subject: [PATCH] vasnprintf: fix potential incorrect errno An adjustment of the previous commit c5c4f53b. * lib/vasnprintf.c (VASNPRINTF): free() generally doesn't set errno, but it can potentially in certain edge cases. Reported by Eric Blake. --- lib/vasnprintf.c | 15 +-- 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c index 223be07..a73fad6 100644 --- a/lib/vasnprintf.c +++ b/lib/vasnprintf.c @@ -5179,18 +5179,21 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, /* SNPRINTF or sprintf failed. Save and use the errno that it has set, if any. */ int saved_errno = errno; +if (saved_errno == 0) + { +if (dp-conversion == 'c' || dp-conversion == 's') + saved_errno = EILSEQ; +else + saved_errno = EINVAL; + } if (!(result == resultbuf || result == NULL)) free (result); if (buf_malloced != NULL) free (buf_malloced); -errno = - (saved_errno != 0 - ? saved_errno - : (dp-conversion == 'c' || dp-conversion == 's' - ? EILSEQ - : EINVAL)); CLEANUP (); + +errno = saved_errno; return NULL; } -- 2.1.0
[PATCH] bootstrap: Allow perl modules in $buildreq
With this patch it is possible to put e.g. perl::XML:XPath - in $buildreq in bootstrap.conf which will cause a check for perl module XML::XPath using: perl -mXML::XPath -e 'exit 0' /dev/null 21 If this fails due to any other error then XML::XPath missing, it is left on the user to fix up his/hers bootstrap.conf. One of the examples might be perl itself missing, which should be in $buildreq and precede any perl::Module specifications. Versioning of perl modules is not supported. Signed-off-by: Martin Kletzander mklet...@redhat.com --- build-aux/bootstrap | 14 +- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/build-aux/bootstrap b/build-aux/bootstrap index ce90bc4..8f948a0 100755 --- a/build-aux/bootstrap +++ b/build-aux/bootstrap @@ -1,6 +1,6 @@ #! /bin/sh # Print a version string. -scriptversion=2013-12-05.23; # UTC +scriptversion=2014-12-08.10; # UTC # Bootstrap this package from checked-out sources. @@ -446,6 +446,7 @@ check_versions() { test $appvar = TAR appvar=AMTAR case $appvar in GZIP) ;; # Do not use $GZIP: it contains gzip options. +PERL::*) ;; # Keep perl modules as-is *) eval app=\${$appvar-$app} ;; esac @@ -463,6 +464,17 @@ check_versions() { ret=1 continue } ;; + # Another check is for perl modules. These can be written as + # e.g. per::XML::XPath in case of XML::XPath module, etc. + perl::*) +# Check for perl modules +app=${app#perl::} +if ! perl -m$app -e 'exit 0' /dev/null 21; then + warn_ Error: perl module '$app' not found + ret=1 +fi +continue +;; esac if [ $req_ver = - ]; then # Merely require app to exist; not all prereq apps are well-behaved -- 2.2.0
Re: [PATCH] bootstrap: Allow perl modules in $buildreq
On 08/12/14 10:42, Martin Kletzander wrote: With this patch it is possible to put e.g. perl::XML:XPath - in $buildreq in bootstrap.conf which will cause a check for perl module XML::XPath looks useful... perl -mXML::XPath -e 'exit 0' /dev/null 21 If this fails due to any other error then XML::XPath missing, it is left on the user to fix up his/hers bootstrap.conf. One of the examples might be perl itself missing, which should be in $buildreq and precede any perl::Module specifications. Versioning of perl modules is not supported. Signed-off-by: Martin Kletzander mklet...@redhat.com --- build-aux/bootstrap | 14 +- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/build-aux/bootstrap b/build-aux/bootstrap index ce90bc4..8f948a0 100755 --- a/build-aux/bootstrap +++ b/build-aux/bootstrap @@ -1,6 +1,6 @@ #! /bin/sh # Print a version string. -scriptversion=2013-12-05.23; # UTC +scriptversion=2014-12-08.10; # UTC # Bootstrap this package from checked-out sources. @@ -446,6 +446,7 @@ check_versions() { test $appvar = TAR appvar=AMTAR case $appvar in GZIP) ;; # Do not use $GZIP: it contains gzip options. +PERL::*) ;; # Keep perl modules as-is *) eval app=\${$appvar-$app} ;; esac @@ -463,6 +464,17 @@ check_versions() { ret=1 continue } ;; + # Another check is for perl modules. These can be written as + # e.g. per::XML::XPath in case of XML::XPath module, etc. s/per/perl/ + perl::*) +# Check for perl modules +app=${app#perl::} +if ! perl -m$app -e 'exit 0' /dev/null 21; then Should we honor $PERL here? + warn_ Error: perl module '$app' not found + ret=1 +fi +continue +;; esac if [ $req_ver = - ]; then # Merely require app to exist; not all prereq apps are well-behaved thanks, Pádraig.
Re: [PATCH] bootstrap: Allow perl modules in $buildreq
On Mon, Dec 08, 2014 at 11:00:37AM +, Pádraig Brady wrote: On 08/12/14 10:42, Martin Kletzander wrote: With this patch it is possible to put e.g. perl::XML:XPath - in $buildreq in bootstrap.conf which will cause a check for perl module XML::XPath looks useful... perl -mXML::XPath -e 'exit 0' /dev/null 21 If this fails due to any other error then XML::XPath missing, it is left on the user to fix up his/hers bootstrap.conf. One of the examples might be perl itself missing, which should be in $buildreq and precede any perl::Module specifications. Versioning of perl modules is not supported. Signed-off-by: Martin Kletzander mklet...@redhat.com --- build-aux/bootstrap | 14 +- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/build-aux/bootstrap b/build-aux/bootstrap index ce90bc4..8f948a0 100755 --- a/build-aux/bootstrap +++ b/build-aux/bootstrap @@ -1,6 +1,6 @@ #! /bin/sh # Print a version string. -scriptversion=2013-12-05.23; # UTC +scriptversion=2014-12-08.10; # UTC # Bootstrap this package from checked-out sources. @@ -446,6 +446,7 @@ check_versions() { test $appvar = TAR appvar=AMTAR case $appvar in GZIP) ;; # Do not use $GZIP: it contains gzip options. +PERL::*) ;; # Keep perl modules as-is *) eval app=\${$appvar-$app} ;; esac @@ -463,6 +464,17 @@ check_versions() { ret=1 continue } ;; + # Another check is for perl modules. These can be written as + # e.g. per::XML::XPath in case of XML::XPath module, etc. s/per/perl/ + perl::*) +# Check for perl modules +app=${app#perl::} +if ! perl -m$app -e 'exit 0' /dev/null 21; then Should we honor $PERL here? That'd be wise. Also there should be PERL=${PERL-perl} in the beginning of the script, I guess, right? Thank you for the review, Martin + warn_ Error: perl module '$app' not found + ret=1 +fi +continue +;; esac if [ $req_ver = - ]; then # Merely require app to exist; not all prereq apps are well-behaved thanks, Pádraig. signature.asc Description: Digital signature
[PATCH v2] bootstrap: Allow perl modules in $buildreq
With this patch it is possible to put e.g. perl::XML:XPath - in $buildreq in bootstrap.conf which will cause a check for perl module XML::XPath using: perl -mXML::XPath -e 'exit 0' /dev/null 21 If this fails due to any other error then XML::XPath missing, it is left on the user to fix up his/hers bootstrap.conf. One of the examples might be perl itself missing, which should be in $buildreq and precede any perl::Module specifications. Versioning of perl modules is not supported. Signed-off-by: Martin Kletzander mklet...@redhat.com --- Notes: v2: - Fix typo s/per::/perl::/ - Honour $PERL if it exists build-aux/bootstrap | 17 - 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/build-aux/bootstrap b/build-aux/bootstrap index 4f0493a..6ab06d4 100755 --- a/build-aux/bootstrap +++ b/build-aux/bootstrap @@ -1,6 +1,6 @@ #! /bin/sh # Print a version string. -scriptversion=2013-12-05.23; # UTC +scriptversion=2014-12-08.11; # UTC # Bootstrap this package from checked-out sources. @@ -42,6 +42,9 @@ export LC_ALL local_gl_dir=gl +# Honour $PERL, but work even if there is none +PERL=${PERL-perl} + me=$0 usage() { @@ -456,6 +459,7 @@ check_versions() { test $appvar = TAR appvar=AMTAR case $appvar in GZIP) ;; # Do not use $GZIP: it contains gzip options. +PERL::*) ;; # Keep perl modules as-is *) eval app=\${$appvar-$app} ;; esac @@ -473,6 +477,17 @@ check_versions() { ret=1 continue } ;; + # Another check is for perl modules. These can be written as + # e.g. perl::XML::XPath in case of XML::XPath module, etc. + perl::*) +# Check for perl modules +app=${app#perl::} +if ! perl -m$app -e 'exit 0' /dev/null 21; then + warn_ Error: perl module '$app' not found + ret=1 +fi +continue +;; esac if [ $req_ver = - ]; then # Merely require app to exist; not all prereq apps are well-behaved -- 2.2.0
[PATCH v3] bootstrap: Allow perl modules in $buildreq
With this patch it is possible to put e.g. perl::XML:XPath - in $buildreq in bootstrap.conf which will cause a check for perl module XML::XPath using: perl -mXML::XPath -e 'exit 0' /dev/null 21 If this fails due to any other error then XML::XPath missing, it is left on the user to fix up his/hers bootstrap.conf. One of the examples might be perl itself missing, which should be in $buildreq and precede any perl::Module specifications. Versioning of perl modules is not supported. Signed-off-by: Martin Kletzander mklet...@redhat.com --- Notes: v3: - Actually use $PERL - s/Check for perl modules/Extract module name/ in comment to de-duplicate redundant info v2: - Fix typo s/per::/perl::/ - Honour $PERL if it exists build-aux/bootstrap | 17 - 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/build-aux/bootstrap b/build-aux/bootstrap index 4f0493a..e0c4ec2 100755 --- a/build-aux/bootstrap +++ b/build-aux/bootstrap @@ -1,6 +1,6 @@ #! /bin/sh # Print a version string. -scriptversion=2013-12-05.23; # UTC +scriptversion=2014-12-08.12; # UTC # Bootstrap this package from checked-out sources. @@ -42,6 +42,9 @@ export LC_ALL local_gl_dir=gl +# Honour $PERL, but work even if there is none +PERL=${PERL-perl} + me=$0 usage() { @@ -456,6 +459,7 @@ check_versions() { test $appvar = TAR appvar=AMTAR case $appvar in GZIP) ;; # Do not use $GZIP: it contains gzip options. +PERL::*) ;; # Keep perl modules as-is *) eval app=\${$appvar-$app} ;; esac @@ -473,6 +477,17 @@ check_versions() { ret=1 continue } ;; + # Another check is for perl modules. These can be written as + # e.g. perl::XML::XPath in case of XML::XPath module, etc. + perl::*) +# Extract module name +app=${app#perl::} +if ! $PERL -m$app -e 'exit 0' /dev/null 21; then + warn_ Error: perl module '$app' not found + ret=1 +fi +continue +;; esac if [ $req_ver = - ]; then # Merely require app to exist; not all prereq apps are well-behaved -- 2.2.0
Re: [PATCH] vasnprintf: fix potential use after free
On 12/07/2014 07:29 PM, Paul Eggert wrote: Pádraig Brady wrote: BTW if free() may reset errno on some platforms then it's probably worth augmenting the gnulib free() wrapper to restore errno if needed, The documented GNU behavior for 'free' allows 'free' to set errno, right? So why should the corresponding gnulib wrapper guarantee behavior above and beyond what GNU implements? Only implicitly (basically, any function that does not explicitly state that errno is left unchanged is free to change errno as a side effect on success). But the POSIX proposal is that free should be one of the functions that guarantees that errno can't be clobbered on success; and GNU should probably implement that now rather than waiting a few years for the POSIX proposal to become standardized. It might make sense to have a variant of 'free' that preserves errno, but we should probably give the variant a different name. 'noerr_free', say. I'm not sure a variant is needed; if we can get glibc to guarantee the POSIX proposal now, then we would merely be guaranteeing sane behavior on all platforms. -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature
Re: [PATCH] vasnprintf: fix potential use after free
On 12/08/2014 07:24 AM, Eric Blake wrote: It might make sense to have a variant of 'free' that preserves errno, but we should probably give the variant a different name. 'noerr_free', say. I'm not sure a variant is needed; if we can get glibc to guarantee the POSIX proposal now, then we would merely be guaranteeing sane behavior on all platforms. Yes, that sounds right.
Re: [PATCH 08/21] get_shared_library_fullname: port to EMX
On 12/04/2014 03:44 AM, Bruno Haible wrote: Thanks. Can you please add this URL as a comment in the patch? For future reference. Of course. Added. Looks good. Thanks. + for specifications of DosQueryModuleName(). */ another typo fix; amended and pushed. At this point, you may be better off reposting your remaining patches as fresh threads, as it is getting hard to find your revisions buried amidst so many other mails. It's okay to post more than one thread, especially if the patches can be subdivided into thematic groups where one group might get reviews faster than another, or where the maintainer for the affected files differs between the groups. If you use 'git send-email -v2', it will make it obvious that you are posting a v2 patch. -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature
Re: [PATCH v3] bootstrap: Allow perl modules in $buildreq
LGTM. Pushed. thanks, Pádraig
Re: [PATCH 07/21] find_executable: port to EMX
On 12/03/2014 03:53 PM, Bruno Haible wrote: KO Myung-Hun submitted: 0001-find_executable-port-to-EMX.patch This patch looks fine now. Thanks. A couple of typos: + for specifications of DosQueryModuleName(). */ s/specifications/specification/ (appeared twice). I added a ChangeLog entry, and pushed with that fixed. -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature
Re: [libvirt] [PATCH] Define __USE_MINGW_ANSI_STDIO in config.h
On 12/02/2014 06:50 AM, Pádraig Brady wrote: It could perhaps be argued that gnulib's 'asprintf' could be defining __USE_MINGW_ANSI_STDIO for us ? Yes, gnulib should be taking advantage of this new mingw development. I independently noticed this mingw feature when looking at the portability of gnulib's ftoastr to mingw. I agree that gnulib should define this. Note ftoastr doesn't depend on any of the gnulib printf modules as that was thought to be overkill for the portability provided, so I'm not sure where to put this define. In the attached I added it to the extensions module and depended on that from both ftoastr and stdio. I went ahead and pushed this patch. Thanks for reviving this topic. -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature
Re: [libvirt] [PATCH] Define __USE_MINGW_ANSI_STDIO in config.h
On 12/08/2014 02:15 PM, Eric Blake wrote: On 12/08/2014 02:10 PM, Pádraig Brady wrote: This was pushed (I think inadvertently). No, it was intentional, done by me with an explanation mail. But it looks like the GNU mail servers are eating my gpg-signed mails (again - I thought we had fixed it a couple weeks ago, but it appears to have resurfaced). I'm sending this one without signature, to see if that helps. Scratch that; today it looks like the mails are just slow on Red Hat's end, and not the GNU servers eating things. (It's always awkward when there's delays in mail queues...) -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature
Re: [PATCH v3] bootstrap: Allow perl modules in $buildreq
On 12/08/2014 05:19 AM, Martin Kletzander wrote: With this patch it is possible to put e.g. perl::XML:XPath - in $buildreq in bootstrap.conf which will cause a check for perl module XML::XPath using: perl -mXML::XPath -e 'exit 0' /dev/null 21 If this fails due to any other error then XML::XPath missing, it is left s/then/than/ on the user to fix up his/hers bootstrap.conf. One of the examples s/hers/her/ might be perl itself missing, which should be in $buildreq and precede any perl::Module specifications. Versioning of perl modules is not supported. Signed-off-by: Martin Kletzander mklet...@redhat.com --- Looks good to me; I've gone ahead and pushed it, after adding a ChangeLog entry (the tiny change notation I added there covers the fact that this contribution does not need copyright papers from you, whether or not it is considered that Red Hat's blanket assignment would apply to your submission). -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature
Re: [PATCH 05/21] spawn: do not include sched.h on OS/2 kLIBC
On 12/04/2014 03:42 AM, Bruno Haible wrote: Like this ? 0001-sched-check-struct-sched_param-in-spawn.h-as-well.patch Yes. This looks perfect now. Thanks! I've pushed this one. -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature
Re: [libvirt] [PATCH] Define __USE_MINGW_ANSI_STDIO in config.h
On 12/02/2014 06:50 AM, Pádraig Brady wrote: GNULIB's 'asprintf' module detected that mingw had the asprintf function, but didn't define the __USE_MINGW_ANSI_STDIO so we got left with the version offering Win32 format specifiers, instead of GNU formats. It could perhaps be argued that gnulib's 'asprintf' could be defining __USE_MINGW_ANSI_STDIO for us ? Yes, gnulib should be taking advantage of this new mingw development. I independently noticed this mingw feature when looking at the portability of gnulib's ftoastr to mingw. I agree that gnulib should define this. Note ftoastr doesn't depend on any of the gnulib printf modules as that was thought to be overkill for the portability provided, so I'm not sure where to put this define. In the attached I added it to the extensions module and depended on that from both ftoastr and stdio. Phooey - with this patch, but NOT a full use of gnulib *printf modules, I run into a new issue: CC event_test-event-test.o ../../../examples/object-events/event-test.c: In function 'myDomainEventRTCChangeCallback': ../../../examples/object-events/event-test.c:329:12: error: unknown conversion type character 'l' in format [-Werror=format=] (intmax_t)offset); ^ where the code in question is using: printf(%s EVENT: Domain %s(%d) rtc change % PRIdMAX \n, __func__, virDomainGetName(dom), virDomainGetID(dom), (intmax_t)offset); Note that this compiled just fine without your patch. It looks like the difference is because gnulib's stdio.h replacement does: # if 0 || 0 _GL_FUNCDECL_RPL (fprintf, int, (FILE *fp, const char *format, ...) _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) _GL_ARG_NONNULL ((1, 2))); # else _GL_FUNCDECL_RPL (fprintf, int, (FILE *fp, const char *format, ...) _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM (2, 3) _GL_ARG_NONNULL ((1, 2))); # endif where, if no fprintf module is used, then we are FORCING the system printf format, so gcc thinks that %lld is unsupported - but at the same time, mingw's inttypes.h has conditional logic that defines PRIdMAX to lld instead of I64d when we have turned on proper printf. It looks like we need to rethink the logic in stdio.h to unconditionally use __gnu_printf__ when we are sure that the mingw define actually makes a difference, so that the rest of the code base can just blindly use %lld. -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature
Re: [libvirt] [PATCH] Define __USE_MINGW_ANSI_STDIO in config.h
On 12/08/2014 04:14 PM, Eric Blake wrote: where, if no fprintf module is used, then we are FORCING the system printf format, so gcc thinks that %lld is unsupported - but at the same time, mingw's inttypes.h has conditional logic that defines PRIdMAX to lld instead of I64d when we have turned on proper printf. It looks like we need to rethink the logic in stdio.h to unconditionally use __gnu_printf__ when we are sure that the mingw define actually makes a difference, so that the rest of the code base can just blindly use %lld. At this point, I'm thinking the stdio module needs a configure-time test to see whether PRIdMAX is equivalent to lld or not, and set a witness preprocessor variable that stdin.in.h then uses to decide between blind use of __gnu_printf__ vs. system __printf__ attributes (since we still want to work on older mingw, that lacks the newer mingw64 magic for supporting %lld). Bummer that the preprocessor can't do string comparison natively. -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature
Re: [PATCH 08/21] get_shared_library_fullname: port to EMX
Eric Blake wrote: On 12/04/2014 03:44 AM, Bruno Haible wrote: Thanks. Can you please add this URL as a comment in the patch? For future reference. Of course. Added. Looks good. Thanks. + for specifications of DosQueryModuleName(). */ another typo fix; amended and pushed. Ooops... So sorry for my poor English. T.T At this point, you may be better off reposting your remaining patches as fresh threads, as it is getting hard to find your revisions buried amidst so many other mails. It's okay to post more than one thread, especially if the patches can be subdivided into thematic groups where one group might get reviews faster than another, or where the maintainer for the affected files differs between the groups. If you use 'git send-email -v2', it will make it obvious that you are posting a v2 patch. Thanks very much for your advice. I'll send rebased patches, soon. -- KO Myung-Hun Using Mozilla SeaMonkey 2.7.2 Under OS/2 Warp 4 for Korean with FixPak #15 In VirtualBox v4.1.32 on Intel Core i7-3615QM 2.30GHz with 8GB RAM Korean OS/2 User Community : http://www.ecomstation.co.kr
Re: [PATCH 07/21] find_executable: port to EMX
Eric Blake wrote: On 12/03/2014 03:53 PM, Bruno Haible wrote: KO Myung-Hun submitted: 0001-find_executable-port-to-EMX.patch This patch looks fine now. Thanks. A couple of typos: + for specifications of DosQueryModuleName(). */ s/specifications/specification/ (appeared twice). I added a ChangeLog entry, and pushed with that fixed. Thanks. -- KO Myung-Hun Using Mozilla SeaMonkey 2.7.2 Under OS/2 Warp 4 for Korean with FixPak #15 In VirtualBox v4.1.32 on Intel Core i7-3615QM 2.30GHz with 8GB RAM Korean OS/2 User Community : http://www.ecomstation.co.kr
[PATCH v2] OS/2 patches
Hi/2. These are rebased OS/2 patches. Review, please... [PATCH 01/14] stdint: check _INTPTR_T_DECLARED before defining [PATCH 02/14] Fix character encoding aliases for OS/2 [PATCH 03/14] relocatable: support UNIXROOT in relocate() on EMX [PATCH 04/14] binary-io: don't put fd in binary mode if it is a [PATCH 05/14] pipe-filter-aux: undefine HAVE_SELECT on KLIBC [PATCH 06/14] w32spawn: clear SHELL_SPECIAL_CHARS and [PATCH 07/14] getdtablesize: do not use getrlimit() on OS/2 kLIBC [PATCH 08/14] wcwidth: fix 'conflicting types' error for `__wcwidth' [PATCH 09/14] utimes: detect utimes() correctly on OS/2 kLIBC [PATCH 10/14] gnulib-tool: fall back into copy if symbolic link is [PATCH 11/14] pipe_filter_ii_execute: port to OS/2 kLIBC [PATCH 12/14] save_cwd: save/restore all CWDs of each drive on EMX [PATCH 13/14] dup, dup2, fcntl: support a directory fd on OS/2 kLIBC [PATCH 14/14] opendir, closedir, dirfd, fdopendir: port to OS/2 kLIBC
[PATCH 02/14] Fix character encoding aliases for OS/2
* lib/config.charset: Remove os2* from case $os in * lib/localcharset.c (get_charset_aliases): Use embedded encoding aliases on OS/2. --- lib/config.charset | 4 +--- lib/localcharset.c | 60 +- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/lib/config.charset b/lib/config.charset index 4e4c7ed..3e6c88f 100644 --- a/lib/config.charset +++ b/lib/config.charset @@ -348,12 +348,10 @@ case $os in #echo sun_eu_greek ? # what is this? echo UTF-8 UTF-8 ;; - freebsd* | os2*) + freebsd*) # FreeBSD 4.2 doesn't have nl_langinfo(CODESET); therefore # localcharset.c falls back to using the full locale name # from the environment variables. -# Likewise for OS/2. OS/2 has XFree86 just like FreeBSD. Just -# reuse FreeBSD's locale data for OS/2. echo C ASCII echo US-ASCII ASCII for l in la_LN lt_LN; do diff --git a/lib/localcharset.c b/lib/localcharset.c index 1c17af0..ba2ac3e 100644 --- a/lib/localcharset.c +++ b/lib/localcharset.c @@ -128,7 +128,7 @@ get_charset_aliases (void) cp = charset_aliases; if (cp == NULL) { -#if !(defined DARWIN7 || defined VMS || defined WINDOWS_NATIVE || defined __CYGWIN__) +#if !(defined DARWIN7 || defined VMS || defined WINDOWS_NATIVE || defined __CYGWIN__ || defined OS2) const char *dir; const char *base = charset.alias; char *file_name; @@ -342,6 +342,64 @@ get_charset_aliases (void) CP54936 \0 GB18030 \0 CP65001 \0 UTF-8 \0; # endif +# if defined OS2 + /* To avoid the troubles of installing a separate file in the same + directory as the DLL and of retrieving the DLL's directory at + runtime, simply inline the aliases here. */ + + cp = bg_BG \0 CP1251 \0 + ca_ES \0 CP850 \0 + cs_SZ \0 CP852 \0 + da_DK \0 CP850 \0 + de_AT \0 CP850 \0 + de_CH \0 CP850 \0 + de_DE \0 CP850 \0 + el_GR \0 CP869 \0 + en_AU \0 CP850 \0 + en_CA \0 CP850 \0 + en_GB \0 CP850 \0 + en_IE \0 CP850 \0 + en_NZ \0 CP850 \0 + en_US \0 CP850 \0 + en_ZA \0 CP850 \0 + es_ES \0 CP850 \0 + es_LA \0 CP850 \0 + et_EE \0 CP922 \0 + fi_FI \0 CP850 \0 + fr_BE \0 CP850 \0 + fr_CA \0 CP850 \0 + fr_CH \0 CP850 \0 + fr_FR \0 CP850 \0 + hr_HR \0 CP852 \0 + hu_HU \0 CP852 \0 + is_IS \0 CP850 \0 + it_CH \0 CP850 \0 + it_IT \0 CP850 \0 + iw_IL \0 CP862 \0 + ja_JP \0 CP943 \0 + ko_KR \0 CP949 \0 + lt_LT \0 ISO-8859-13 \0 + lv_LV \0 ISO-8859-13 \0 + mk_MK \0 CP855 \0 + nl_BE \0 CP850 \0 + nl_NL \0 CP850 \0 + no_NO \0 CP850 \0 + pl_PL \0 CP852 \0 + pt_BR \0 CP850 \0 + pt_PT \0 CP850 \0 + ro_RO \0 CP852 \0 + ru_RU \0 CP866 \0 + sh_BA \0 CP852 \0 + sk_SK \0 CP852 \0 + sl_SI \0 CP852 \0 + sq_AL \0 CP850 \0 + sr_SP \0 CP855 \0 + sv_SE \0 CP850 \0 + th_TH \0 CP874 \0 + tr_TR \0 CP857 \0 + zh_CN \0 GB2312 \0 + zh_TW \0 CP950 \0; +# endif #endif charset_aliases = cp; -- 1.8.5.2
[PATCH 05/14] pipe-filter-aux: undefine HAVE_SELECT on KLIBC
On OS/2 kLIBC, select() works only on sockets. * lib/pipe-filter-aux.h (HAVE_SELECT): Undefine on OS/2 kLIBC. --- lib/pipe-filter-aux.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/pipe-filter-aux.h b/lib/pipe-filter-aux.h index 8f2a707..ee63ac8 100644 --- a/lib/pipe-filter-aux.h +++ b/lib/pipe-filter-aux.h @@ -35,8 +35,9 @@ _GL_INLINE_HEADER_BEGIN looping while waiting for the child. Not good. But hardly any platform lacks select() nowadays.) */ -/* On BeOS select() works only on sockets, not on normal file descriptors. */ -#ifdef __BEOS__ +/* On BeOS and OS/2 kLIBC select() works only on sockets, not on normal file + descriptors. */ +#if defined __BEOS__ || defined __KLIBC__ # undef HAVE_SELECT #endif -- 1.8.5.2
[PATCH 03/14] relocatable: support UNIXROOT in relocate() on EMX
UNIXROOT is used to specify a drive of a root of FHS. So if a path is started with '/', then it should be translated to $UNIXROOT/. * lib/relocatable.c (relocate): Prepend $UNIXROOT to pathname if it is started with '/' on EMX. --- lib/relocatable.c | 21 + 1 file changed, 21 insertions(+) diff --git a/lib/relocatable.c b/lib/relocatable.c index 6c6ea1c..1d6fdd5 100644 --- a/lib/relocatable.c +++ b/lib/relocatable.c @@ -537,6 +537,27 @@ relocate (const char *pathname) } } } + +#ifdef __EMX__ + if (pathname ISSLASH (pathname[0])) +{ + const char *unixroot = getenv (UNIXROOT); + + if (unixroot HAS_DEVICE (unixroot) !unixroot[2]) +{ + char *result = (char *) xmalloc (2 + strlen (pathname) + 1); +#ifdef NO_XMALLOC + if (result != NULL) +#endif +{ + strcpy (result, unixroot); + strcpy (result + 2, pathname); + return result; +} +} +} +#endif + /* Nothing to relocate. */ return pathname; } -- 1.8.5.2
[PATCH 01/14] stdint: check _INTPTR_T_DECLARED before defining intptr_t and uintptr_t
OS/2 kLIBC's stdint.h defines _INTPTR_T_DECLARED and needs its own definitions of intptr_t and uintptr_t (which use int and unsigned) to avoid clashes with declarations of system functions like sbrk. * lib/stdint.in.h (intptr_t, uintptr_t): Check _INTPTR_T_DECLARED before defining them. --- lib/stdint.in.h | 13 + 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/stdint.in.h b/lib/stdint.in.h index 98ee423..79f67a6 100644 --- a/lib/stdint.in.h +++ b/lib/stdint.in.h @@ -288,12 +288,17 @@ typedef gl_uint_fast32_t gl_uint_fast16_t; /* 7.18.1.4. Integer types capable of holding object pointers */ -#undef intptr_t -#undef uintptr_t +/* kLIBC's stdint.h defines _INTPTR_T_DECLARED and needs its own + definitions of intptr_t and uintptr_t (which use int and unsigned) + to avoid clashes with declarations of system functions like sbrk. */ +#ifndef _INTPTR_T_DECLARED +# undef intptr_t +# undef uintptr_t typedef long int gl_intptr_t; typedef unsigned long int gl_uintptr_t; -#define intptr_t gl_intptr_t -#define uintptr_t gl_uintptr_t +# define intptr_t gl_intptr_t +# define uintptr_t gl_uintptr_t +#endif /* 7.18.1.5. Greatest-width integer types */ -- 1.8.5.2
[PATCH 06/14] w32spawn: clear SHELL_SPECIAL_CHARS and SHELL_SPACE_CHAR on OS/2 kLIBC
spawn() on OS/2 kLIBC is not silly like one on Windows * libc/w32spawn.h (SHELL_SPECIAL_CHARS, SHELL_SPACE_CHAR): Set both to empty string on OS/2 kLIBC. --- lib/w32spawn.h | 9 +++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/w32spawn.h b/lib/w32spawn.h index 0cad232..16f1251 100644 --- a/lib/w32spawn.h +++ b/lib/w32spawn.h @@ -123,8 +123,13 @@ undup_safer_noinherit (int tempfd, int origfd) - mingw programs that have a global variable 'int _CRT_glob = 0;', - Cygwin programs, when invoked from a Cygwin program. */ -#define SHELL_SPECIAL_CHARS \\\ \001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037*? -#define SHELL_SPACE_CHARS \001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037 +#ifndef __KLIBC__ +# define SHELL_SPECIAL_CHARS \\\ \001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037*? +# define SHELL_SPACE_CHARS \001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037 +#else +# define SHELL_SPECIAL_CHARS +# define SHELL_SPACE_CHARS +#endif static char ** prepare_spawn (char **argv) { -- 1.8.5.2
[PATCH 09/14] utimes: detect utimes() correctly on OS/2 kLIBC
utimes() of OS/2 kLIBC has some limitations. 1. OS/2 itself supports a file date since 1980 year. 2. OS/2 itself supports even seconds for a file time. 3. utimes() of OS/2 kLIBC does not work on an opened file. * m4/utimes.m4: Detect utimes() correctly on OS/2 kLIBC. --- m4/utimes.m4 | 13 ++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/m4/utimes.m4 b/m4/utimes.m4 index c361357..ce6435c 100644 --- a/m4/utimes.m4 +++ b/m4/utimes.m4 @@ -1,5 +1,5 @@ # Detect some bugs in glibc's implementation of utimes. -# serial 3 +# serial 4 dnl Copyright (C) 2003-2005, 2009-2014 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation @@ -45,7 +45,9 @@ main () { int result = 0; char const *file = conftest.utimes; - static struct timeval timeval[2] = {{9, 10}, {99, 99}}; + /* On OS/2, a file date should be since 1980 year and even seconds */ + static struct timeval timeval[2] = {{315500400 + 10, 10}, + {315500400 + 100, 98}}; /* Test whether utimes() essentially works. */ { @@ -82,11 +84,16 @@ main () result |= 1; else if (fstat (fd, st0) != 0) result |= 1; +/* utimes() of OS/2 kLIBC does not work on an opened file */ +else if (close (fd) != 0) + result |= 1; else if (utimes (file, timeval) != 0) result |= 2; else if (utimes (file, NULL) != 0) result |= 8; -else if (fstat (fd, st1) != 0) +else if (lstat (file, st1) != 0) + result |= 1; +else if ((fd = open (file, O_WRONLY)) 0) result |= 1; else if (write (fd, \n, 1) != 1) result |= 1; -- 1.8.5.2
[PATCH 04/14] binary-io: don't put fd in binary mode if it is a console on EMX
* lib/binary-io.h (SET_BINARY): Don't put fd in binary mode if it is a console on EMX. --- lib/binary-io.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/binary-io.h b/lib/binary-io.h index 7928f8c..696cdf9 100644 --- a/lib/binary-io.h +++ b/lib/binary-io.h @@ -60,7 +60,7 @@ set_binary_mode (int fd, int mode) /* SET_BINARY (fd); changes the file descriptor fd to perform binary I/O. */ -#ifdef __DJGPP__ +#if defined __DJGPP__ || defined __EMX__ # include unistd.h /* declares isatty() */ /* Avoid putting stdin/stdout in binary mode if it is connected to the console, because that would make it impossible for the user -- 1.8.5.2
[PATCH 11/14] pipe_filter_ii_execute: port to OS/2 kLIBC
Pipes on kLIBC does not support O_NONBLOCK like Win32. * lib/pipe-filter-ii.c (start_wrapper, _beginthreadex, CloseHandle, WaiForSingleObject, WaitForMultipleObjects): New on OS/2 kLIBC. Reuse Win32 codes on OS/2 kLIBC. * lib/spawn-pipe.c: Reuse Win32 codes on OS/2 kLIBC. * lib/w32spawn.h: Do not include windows.h on OS/2 kLIBC. --- lib/pipe-filter-ii.c | 133 +-- lib/spawn-pipe.c | 6 ++- lib/w32spawn.h | 6 ++- 3 files changed, 137 insertions(+), 8 deletions(-) diff --git a/lib/pipe-filter-ii.c b/lib/pipe-filter-ii.c index db398d2..27037e5 100644 --- a/lib/pipe-filter-ii.c +++ b/lib/pipe-filter-ii.c @@ -27,6 +27,127 @@ #include unistd.h #if (defined _WIN32 || defined __WIN32__) ! defined __CYGWIN__ # include windows.h +#elif defined __KLIBC__ +# define INCL_DOS +# include os2.h + +/* Simple implementation of Win32 APIs */ + +# define WINAPI + +typedef struct _HANDLE +{ +TID tid; +HEV hevDone; +unsigned int WINAPI (*start) (void *); +void *arg; +} *HANDLE; + +typedef ULONG DWORD; + +static void +start_wrapper (void *arg) +{ + HANDLE h = (HANDLE) arg; + + h-start (h-arg); + + DosPostEventSem (h-hevDone); + _endthread (); +} + +static HANDLE +_beginthreadex (void *s, unsigned n, unsigned int WINAPI (*start) (void *), +void *arg, unsigned fl, unsigned *th) +{ + HANDLE h; + + h = malloc (sizeof (*h)); + if (!h) +return NULL; + + if (DosCreateEventSem (NULL, h-hevDone, 0, FALSE )) +goto exit_free; + + h-start = start; + h-arg = arg; + + h-tid = _beginthread (start_wrapper, NULL, n, (void *) h); + if (h-tid == -1) +goto exit_close_event_sem; + + return h; + +exit_close_event_sem: + DosCloseEventSem (h-hevDone); + +exit_free: + free (h); + + return NULL; +} + +static BOOL +CloseHandle (HANDLE h) +{ + DosCloseEventSem (h-hevDone); + free (h); +} + +# define _endthreadex(x) return (x) +# define TerminateThread(h, e) DosKillThread (h-tid) + +# define GetLastError() -1 + +# ifndef ERROR_NO_DATA +# define ERROR_NO_DATA 232 +# endif + +# define INFINITE SEM_INDEFINITE_WAIT +# define WAIT_OBJECT_0 0 + +static DWORD +WaitForSingleObject (HANDLE h, DWORD ms) +{ + return DosWaitEventSem (h-hevDone, ms) == 0 ? WAIT_OBJECT_0 : (DWORD) -1; +} + +static DWORD +WaitForMultipleObjects (DWORD nCount, const HANDLE *pHandles, BOOL bWaitAll, +DWORD ms) +{ +HMUX hmux; +PSEMRECORD psr; +ULONG ulUser; +ULONG rc = (ULONG) -1; +DWORD i; + +psr = malloc (sizeof (*psr) * nCount); +if (!psr) + goto exit_return; + +for (i = 0; i nCount; ++i) + { +psr[i].hsemCur = (HSEM) pHandles[i]-hevDone; +psr[i].ulUser = WAIT_OBJECT_0 + i; + } + +if (DosCreateMuxWaitSem (NULL, hmux, nCount, psr, + bWaitAll ? DCMW_WAIT_ALL : DCMW_WAIT_ANY)) + goto exit_free; + +rc = DosWaitMuxWaitSem (hmux, ms, ulUser); +DosCloseMuxWaitSem (hmux); + +exit_free: +free (psr); + +exit_return: +if (rc) +return (DWORD) -1; + +return ulUser; +} #else # include signal.h # include sys/select.h @@ -41,7 +162,8 @@ #include pipe-filter-aux.h -#if (defined _WIN32 || defined __WIN32__) ! defined __CYGWIN__ +#if (defined _WIN32 || defined __WIN32__) ! defined __CYGWIN__ \ +|| defined __KLIBC__ struct locals { @@ -143,7 +265,8 @@ pipe_filter_ii_execute (const char *progname, { pid_t child; int fd[2]; -#if !((defined _WIN32 || defined __WIN32__) ! defined __CYGWIN__) +#if !((defined _WIN32 || defined __WIN32__) ! defined __CYGWIN__ \ + || defined __KLIBC__) struct sigaction orig_sigpipe_action; #endif @@ -154,7 +277,8 @@ pipe_filter_ii_execute (const char *progname, if (child == -1) return -1; -#if (defined _WIN32 || defined __WIN32__) ! defined __CYGWIN__ +#if (defined _WIN32 || defined __WIN32__) ! defined __CYGWIN__ \ +|| defined __KLIBC__ /* Native Windows API. */ /* Pipes have a non-blocking mode, see function SetNamedPipeHandleState and the article Named Pipe Type, Read, and Wait Modes, but Microsoft's @@ -462,7 +586,8 @@ pipe_filter_ii_execute (const char *progname, { int saved_errno = errno; close (fd[1]); -#if !((defined _WIN32 || defined __WIN32__) ! defined __CYGWIN__) +#if !((defined _WIN32 || defined __WIN32__) ! defined __CYGWIN__ \ + || defined __KLIBC__) if (sigaction (SIGPIPE, orig_sigpipe_action, NULL) 0) abort (); #endif diff --git a/lib/spawn-pipe.c b/lib/spawn-pipe.c index 656980d..ab7cc18 100644 --- a/lib/spawn-pipe.c +++ b/lib/spawn-pipe.c @@ -35,7 +35,8 @@ #define _(str) gettext (str) -#if (defined _WIN32 || defined __WIN32__) ! defined __CYGWIN__ +#if (defined _WIN32 || defined __WIN32__) ! defined __CYGWIN__ \ +|| defined __KLIBC__ /* Native Windows API. */ # include process.h @@ -109,7 +110,8 @@ create_pipe (const char *progname,
[PATCH 10/14] gnulib-tool: fall back into copy if symbolic link is not supported
And warn about it. * gnulib-tool (have_symlink_support): New. (symbolic, lsymbolic): Clear on systems not supporting symbolic link. --- gnulib-tool | 20 1 file changed, 20 insertions(+) diff --git a/gnulib-tool b/gnulib-tool index 2641378..c5a4c87 100755 --- a/gnulib-tool +++ b/gnulib-tool @@ -898,6 +898,16 @@ if test X$1 = X--no-reexec; then shift fi +# Check if symbolic link is supported +have_symlink_support=false +rm -f symlink$$.file symlink$$ +if (echo symlink$$.file) 2/dev/null; then + if ln -s symlink$$.file symlink$$ 2/dev/null; then +have_symlink_support=true + fi +fi +rm -f symlink$$.file symlink$$ + # Unset CDPATH. Otherwise, output from 'cd dir' can surprise callers. (unset CDPATH) /dev/null 21 unset CDPATH @@ -1355,6 +1365,16 @@ fi echo gnulib-tool: option --conditional-dependencies is not supported with --with-tests 12 func_exit 1 fi + # Warn if symbolic link is requested on a system not supporting it. + # And fall back into copy. + if { test -n $symbolic || test -n $lsymbolic ; } \ + ! $have_symlink_support ; then +echo gnulib-tool: symbolic link is not supported on this system. 12 +echo Copy will be performed instead. 12 + +symbolic= +lsymbolic= + fi # Determine the minimum supported autoconf version from the project's # configure.ac. -- 1.8.5.2
[PATCH 08/14] wcwidth: fix 'conflicting types' error for `__wcwidth' on OS/2 kLIBC
wchar_t(unsigned short) is defined differently from wint_t(int) on OS/2 kLIBC. * lib/wcwidth.c (wcwidth): Undefine on OS/2 kLIBC. --- lib/wcwidth.c | 7 +++ 1 file changed, 7 insertions(+) diff --git a/lib/wcwidth.c b/lib/wcwidth.c index d7837bb..2f8dc26 100644 --- a/lib/wcwidth.c +++ b/lib/wcwidth.c @@ -26,6 +26,13 @@ #include streq.h #include uniwidth.h +#ifdef __KLIBC__ +/* To avoid 'conflicting types' error for `__wcwidth' on OS/2 kLIBC. + wchar_t(unsigned short) is defined differently from wint_t(int) on + OS/2 kLIBC. */ +# undef wcwidth +#endif + int wcwidth (wchar_t wc) #undef wcwidth -- 1.8.5.2
[PATCH 07/14] getdtablesize: do not use getrlimit() on OS/2 kLIBC
getrlimit() implementation of kLIBC is buggy. For examples, it crashes due to 'stack overflow' or 'SIGSEGV' when used in GNU M4. So just use getdtablesize() on kLIBC. * lib/getdtablesize.c (rpl_getdtablesize): Do not use getrlimit() on OS/2 kLIBC. --- lib/getdtablesize.c | 5 + 1 file changed, 5 insertions(+) diff --git a/lib/getdtablesize.c b/lib/getdtablesize.c index f0c6271..07e9d57 100644 --- a/lib/getdtablesize.c +++ b/lib/getdtablesize.c @@ -92,6 +92,10 @@ getdtablesize (void) int rpl_getdtablesize(void) { +/* getrlimit() implementation of kLIBC is buggy. For examples, it crashes + due to 'stack overflow' or 'SIGSEGV' when used in GNU M4. So just use + getdtablesize() on kLIBC. */ +# ifndef __KLIBC__ /* To date, this replacement is only compiled for Cygwin 1.7.25, which auto-increased the RLIMIT_NOFILE soft limit until it hits the compile-time constant hard limit of 3200. Although @@ -101,6 +105,7 @@ rpl_getdtablesize(void) struct rlimit lim; if (!getrlimit (RLIMIT_NOFILE, lim) lim.rlim_max != RLIM_INFINITY) return lim.rlim_max; +# endif return getdtablesize (); } -- 1.8.5.2
[PATCH 13/14] dup, dup2, fcntl: support a directory fd on OS/2 kLIBC
On OS/2 kLIBC, dup(), dup2() and fcntl() do not work on a directory fd. * lib/dup.c (dup_nothrow): New. * lib/dup2.c (klibc_dup2dirfd): New. dup2() for a directory fd. (klibc_dup2): New. * lib/fcntl.c (klibc_fcntl): New. * m4/dup.m4 (gl_FUNC_DUP): Check if dup() works on a directory fd. * m4/dup2.m4 (gl_FUNC_DUP2): Check if dup2() works on a directory fd. * m4/fcntl.m4 (gl_FUNC_FCNTL): Check if F_DUPFD works on a directory fd. --- lib/dup.c | 25 ++ lib/dup2.c | 51 lib/fcntl.c | 87 + m4/dup.m4 | 30 - m4/dup2.m4 | 15 ++- m4/fcntl.m4 | 14 +- 6 files changed, 219 insertions(+), 3 deletions(-) diff --git a/lib/dup.c b/lib/dup.c index c813df6..a2e43ec 100644 --- a/lib/dup.c +++ b/lib/dup.c @@ -45,6 +45,31 @@ dup_nothrow (int fd) return result; } +#elif defined __KLIBC__ +# include fcntl.h +# include sys/stat.h + +# include InnoTekLIBC/backend.h + +static int +dup_nothrow (int fd) +{ + int dupfd; + struct stat sbuf; + + dupfd = dup (fd); + if (dupfd == -1 errno == ENOTSUP \ + !fstat (fd, sbuf) S_ISDIR (sbuf.st_mode)) +{ + char path[_MAX_PATH]; + + /* Get a path from fd */ + if (!__libc_Back_ioFHToPath (fd, path, sizeof (path))) + dupfd = open (path, O_RDONLY); +} + + return dupfd; +} #else # define dup_nothrow dup #endif diff --git a/lib/dup2.c b/lib/dup2.c index 7de6805..a1fff0a 100644 --- a/lib/dup2.c +++ b/lib/dup2.c @@ -85,6 +85,57 @@ ms_windows_dup2 (int fd, int desired_fd) # define dup2 ms_windows_dup2 +# elif defined __KLIBC__ + +# include InnoTekLIBC/backend.h + +static int +klibc_dup2dirfd (int fd, int desired_fd) +{ + int tempfd; + int dupfd; + + tempfd = open (NUL, O_RDONLY); + if (tempfd == -1) +return -1; + + if (tempfd == desired_fd) +{ + close (tempfd); + + char path[_MAX_PATH]; + if (__libc_Back_ioFHToPath (fd, path, sizeof (path))) +return -1; + + return open(path, O_RDONLY); +} + + dupfd = klibc_dup2dirfd (fd, desired_fd); + + close (tempfd); + + return dupfd; +} + +static int +klibc_dup2 (int fd, int desired_fd) +{ + int dupfd; + struct stat sbuf; + + dupfd = dup2 (fd, desired_fd); + if (dupfd == -1 errno == ENOTSUP \ + !fstat (fd, sbuf) S_ISDIR (sbuf.st_mode)) +{ + close (desired_fd); + + return klibc_dup2dirfd (fd, desired_fd); +} + + return dupfd; +} + +# define dup2 klibc_dup2 # endif int diff --git a/lib/fcntl.c b/lib/fcntl.c index 1e35dd1..1f88b95 100644 --- a/lib/fcntl.c +++ b/lib/fcntl.c @@ -162,6 +162,93 @@ dupfd (int oldfd, int newfd, int flags) } #endif /* W32 */ +#ifdef __KLIBC__ + +# define INCL_DOS +# include os2.h + +static int +klibc_fcntl (int fd, int action, /* arg */...) +{ + va_list arg_ptr; + int arg; + struct stat sbuf; + int result = -1; + + va_start (arg_ptr, action); + arg = va_arg (arg_ptr, int); + result = fcntl (fd, action, arg); + /* EPERM for F_DUPFD, ENOTSUP for others */ + if (result == -1 (errno == EPERM || errno == ENOTSUP) \ + !fstat (fd, sbuf) S_ISDIR (sbuf.st_mode)) + { +ULONG ulMode; + +switch (action) + { + case F_DUPFD: +/* Find available fd */ +while (fcntl (arg, F_GETFL) != -1 || errno != EBADF) + arg++; + +result = dup2 (fd, arg); +break; + + /* Using underlying APIs is right ? */ + case F_GETFD: +if (DosQueryFHState (fd, ulMode)) + break; + +result = (ulMode OPEN_FLAGS_NOINHERIT) ? FD_CLOEXEC : 0; +break; + + case F_SETFD: +if (arg ~FD_CLOEXEC) + break; + +if (DosQueryFHState (fd, ulMode)) + break; + +if (arg FD_CLOEXEC) + ulMode |= OPEN_FLAGS_NOINHERIT; +else + ulMode = ~OPEN_FLAGS_NOINHERIT; + +/* Filter supported flags. */ +ulMode = OPEN_FLAGS_WRITE_THROUGH | OPEN_FLAGS_FAIL_ON_ERROR \ + | OPEN_FLAGS_NO_CACHE | OPEN_FLAGS_NOINHERIT; + +if (DosSetFHState (fd, ulMode)) + break; + +result = 0; +break; + + case F_GETFL: +result = 0; +break; + + case F_SETFL: +if (arg != 0) + break; + +result = 0; +break; + + default : +errno = EINVAL; +break; + } + } + + va_end (arg_ptr); + + return result; +} + +# define fcntl klibc_fcntl +#endif + /* Perform the specified ACTION on the file descriptor FD, possibly using the argument ARG further described below. This replacement handles the following actions, and forwards all others on to the diff --git a/m4/dup.m4 b/m4/dup.m4 index 9393bc5..03ee089 100644 --- a/m4/dup.m4 +++ b/m4/dup.m4 @@ -1,4 +1,4 @@ -# dup.m4 serial 3 +# dup.m4 serial 4 dnl Copyright (C) 2011-2014 Free Software Foundation, Inc. dnl This file is free software; the Free Software
[PATCH 12/14] save_cwd: save/restore all CWDs of each drive on EMX
On OS/2, there are maximum 26 CWDs, one CWD per drive[A to Z]. So it is needed to save and restore all of them as well as a CWD of a current drive. For examples, 1. CWD is C:\CWD 2. Call save_cwd() 3. Change drive to drive D: whose CWD was D:\ 4. Change directory to D:\CWD 5. Now, CWD is D:\CWD 6. Call restore_cwd() 7. Now CWD is C:\CWD. But CWD of drive D: is still D:\CWD not D:\. * lib/save-cwd.c (save_cwd): Save all CWDs of each drive. (restore_cwd): Restore all CWDs of each drive. (free_cwd): Free allocated name_with_drvie. * lib/save-cwd.h (struct save_cwd): Add current_drive and name_with_drive member. --- lib/save-cwd.c | 50 ++ lib/save-cwd.h | 4 2 files changed, 54 insertions(+) diff --git a/lib/save-cwd.c b/lib/save-cwd.c index 7aafacd..5eca000 100644 --- a/lib/save-cwd.c +++ b/lib/save-cwd.c @@ -62,6 +62,36 @@ int save_cwd (struct saved_cwd *cwd) { +#ifdef __EMX__ + /* On OS/2, there are maximum 26 CWDs, one CWD per drive[A to Z]. Here save + all the CWDs of each drive. */ + + char drive; + + /* Save a current drive. */ + cwd-current_drive = _getdrive (); + + /* Save CWD with a drive name of each drive. */ + for (drive = 0; drive = 'Z' - 'A'; drive++) +{ + /* _chdrive() always returns 0. */ + _chdrive (drive + 'A'); + + /* Ignore ENOENT due to empty removable drives such as CD-ROM. */ + if (!(cwd-name_with_drive[drive] = _getcwd2 (NULL, 0)) + errno == ENOMEM) +{ + while (drive-- 0) +free (cwd-name_with_drive[drive]); + + return -1; +} +} + + /* Restore a current drive. */ + _chdrive (cwd-current_drive); +#endif + cwd-name = NULL; cwd-desc = open (., O_SEARCH); @@ -84,6 +114,19 @@ save_cwd (struct saved_cwd *cwd) int restore_cwd (const struct saved_cwd *cwd) { +#ifdef __EMX__ + char drive; + + /* Restore CWD of each drive. */ + for (drive = 0; drive = 'Z' - 'A'; drive++) +if (cwd-name_with_drive[drive]) + if (chdir_long (cwd-name_with_drive[drive])) +return -1; + + /* Restore a current drive. */ + _chdrive (cwd-current_drive); +#endif + if (0 = cwd-desc) return fchdir (cwd-desc); else @@ -93,6 +136,13 @@ restore_cwd (const struct saved_cwd *cwd) void free_cwd (struct saved_cwd *cwd) { +#ifdef __EMX__ + char drive; + + for (drive = 0; drive = 'Z' - 'A'; drive++) +free (cwd-name_with_drive[drive]); +#endif + if (cwd-desc = 0) close (cwd-desc); free (cwd-name); diff --git a/lib/save-cwd.h b/lib/save-cwd.h index 6b84e46..492772f 100644 --- a/lib/save-cwd.h +++ b/lib/save-cwd.h @@ -25,6 +25,10 @@ struct saved_cwd { int desc; char *name; +# ifdef __EMX__ +char current_drive; +char *name_with_drive['Z' - 'A' + 1]; /* for drive A to Z */ +# endif }; int save_cwd (struct saved_cwd *cwd); -- 1.8.5.2
[PATCH 14/14] opendir, closedir, dirfd, fdopendir: port to OS/2 kLIBC
* lib/closedir.c (closedir): Unregister fd if closedir() succeeds. * lib/dirent.in.h (_gl_register_dirp_fd, _gl_unregister_dirp_fd): Declare on kLIBC. * lib/dirfd.c (struct dirp_fd_list): New. Structures to keep track of fd associated with dirp. (_gl_register_dirp_fd): New. Register fd associated with dirp to dirp_fd_list. (_gl_unregister_dirp_fd): New. Unregister fd with closing it. (dirfd): Implemented for kLIBC. * lib/fdopendir.c (fdopendir): Implemented for kLIBC. * lib/opendir.c (opendir): New. Register fd and dirp pair if open() succeeds. * m4/closedir.m4 (gl_FUNC_CLOSEDIR): Replace if OS/2. * m4/dirfd.m4 (gl_FUNC_DIRFD): Likewise. * m4/opendir.m4 (gl_FUNC_OPENDIR): Likewise. * modules/closedir (Depends-on): Add dirfd. * modules/dirfd (Depends-on): Add 'test $REPLACE_DIRFD = 1' to errno condition. (configure.ac): Add dirfd to LIBOBJS if $REPLACE_DIRFD = 1 as well. * modules/fdopendir (Depends-on): Add dirfd. * modules/opendir (Depends-on): Add dirfd. --- lib/closedir.c| 6 - lib/dirent.in.h | 7 ++ lib/dirfd.c | 68 +++ lib/fdopendir.c | 36 + lib/opendir.c | 21 + m4/closedir.m4| 9 +++- m4/dirfd.m4 | 8 --- m4/opendir.m4 | 9 +++- modules/closedir | 1 + modules/dirfd | 5 ++-- modules/fdopendir | 1 + modules/opendir | 1 + 12 files changed, 164 insertions(+), 8 deletions(-) diff --git a/lib/closedir.c b/lib/closedir.c index 940c6f9..b40181c 100644 --- a/lib/closedir.c +++ b/lib/closedir.c @@ -39,7 +39,7 @@ int closedir (DIR *dirp) { -# if REPLACE_FCHDIR +# if REPLACE_FCHDIR || defined __KLIBC__ int fd = dirfd (dirp); # endif int retval; @@ -49,6 +49,10 @@ closedir (DIR *dirp) retval = closedir (dirp); +# ifdef __KLIBC__ + if (!retval) +_gl_unregister_dirp_fd (fd); +# endif #else if (dirp-current != INVALID_HANDLE_VALUE) diff --git a/lib/dirent.in.h b/lib/dirent.in.h index 4822d6b..cce86d9 100644 --- a/lib/dirent.in.h +++ b/lib/dirent.in.h @@ -156,6 +156,13 @@ _GL_WARN_ON_USE (closedir, closedir is not portable - # endif _GL_FUNCDECL_RPL (dirfd, int, (DIR *) _GL_ARG_NONNULL ((1))); _GL_CXXALIAS_RPL (dirfd, int, (DIR *)); + +# ifdef __KLIBC__ +/* Gnulib internal hooks needed to maintain the dirfd metadata. */ +_GL_EXTERN_C int _gl_register_dirp_fd (int fd, DIR *dirp) + _GL_ARG_NONNULL ((2)); +_GL_EXTERN_C void _gl_unregister_dirp_fd (int fd); +# endif # else # if defined __cplusplus defined GNULIB_NAMESPACE defined dirfd /* dirfd is defined as a macro and not as a function. diff --git a/lib/dirfd.c b/lib/dirfd.c index 4d37928..aa6514f 100644 --- a/lib/dirfd.c +++ b/lib/dirfd.c @@ -22,11 +22,79 @@ #include dirent.h #include errno.h +#ifdef __KLIBC__ +# include stdlib.h +# include io.h + +static struct dirp_fd_list +{ + DIR *dirp; + int fd; + struct dirp_fd_list *next; +} *dirp_fd_start = NULL; + +/* Register fd associated with dirp to dirp_fd_list. */ +int +_gl_register_dirp_fd (int fd, DIR *dirp) +{ + struct dirp_fd_list *new_dirp_fd; + + new_dirp_fd = malloc (sizeof (*new_dirp_fd)); + if (!new_dirp_fd) +return -1; + + new_dirp_fd-dirp = dirp; + new_dirp_fd-fd = fd; + new_dirp_fd-next = dirp_fd_start; + + dirp_fd_start = new_dirp_fd; + + return 0; +} + +/* Unregister fd from dirp_fd_list with closing it */ +void +_gl_unregister_dirp_fd (int fd) +{ + struct dirp_fd_list *dirp_fd; + struct dirp_fd_list *dirp_fd_prev; + + for (dirp_fd_prev = NULL, dirp_fd = dirp_fd_start; dirp_fd; + dirp_fd_prev = dirp_fd, dirp_fd = dirp_fd-next) +{ + if (dirp_fd-fd == fd) +{ + if (dirp_fd_prev) +dirp_fd_prev-next = dirp_fd-next; + else /* dirp_fd == dirp_fd_start */ +dirp_fd_start = dirp_fd_start-next; + + close (fd); + free (dirp_fd); + break; +} +} +} +#endif + int dirfd (DIR *dir_p) { int fd = DIR_TO_FD (dir_p); if (fd == -1) +#ifndef __KLIBC__ errno = ENOTSUP; +#else +{ + struct dirp_fd_list *dirp_fd; + + for (dirp_fd = dirp_fd_start; dirp_fd; dirp_fd = dirp_fd-next) +if (dirp_fd-dirp == dir_p) + return dirp_fd-fd; + + errno = EINVAL; +} +#endif + return fd; } diff --git a/lib/fdopendir.c b/lib/fdopendir.c index b6c94a0..80ec4cf 100644 --- a/lib/fdopendir.c +++ b/lib/fdopendir.c @@ -62,6 +62,41 @@ static DIR *fd_clone_opendir (int, struct saved_cwd const *); If this function returns successfully, FD is under control of the dirent.h system, and the caller should not close or modify the state of FD other than by the dirent.h functions. */ +# ifdef __KLIBC__ +# include InnoTekLIBC/backend.h + +DIR * +fdopendir (int fd) +{ + char path[_MAX_PATH]; + DIR *dirp; + + /* Get a path from fd */ + if (__libc_Back_ioFHToPath (fd, path, sizeof (path))) +return NULL; + + dirp = opendir (path); + if (!dirp) +
Re: [PATCH 03/14] relocatable: support UNIXROOT in relocate() on EMX
On Tue, Dec 09, 2014 at 10:40:48AM +0900, KO Myung-Hun wrote: UNIXROOT is used to specify a drive of a root of FHS. So if a path is started with '/', then it should be translated to $UNIXROOT/. * lib/relocatable.c (relocate): Prepend $UNIXROOT to pathname if it is started with '/' on EMX. As one of the maintainers of the relocatable modules, the code in this patch seems reasonable to me. I don't know enough about OS/2 or EMX to know whether $UNIXROOT is a customary variable or whether this is a correct context for using it. Can you assure me that you've thought about those?
Re: [PATCH 03/14] relocatable: support UNIXROOT in relocate() on EMX
Ben Pfaff wrote: On Tue, Dec 09, 2014 at 10:40:48AM +0900, KO Myung-Hun wrote: UNIXROOT is used to specify a drive of a root of FHS. So if a path is started with '/', then it should be translated to $UNIXROOT/. * lib/relocatable.c (relocate): Prepend $UNIXROOT to pathname if it is started with '/' on EMX. As one of the maintainers of the relocatable modules, the code in this patch seems reasonable to me. I don't know enough about OS/2 or EMX to know whether $UNIXROOT is a customary variable or whether this is a correct context for using it. Can you assure me that you've thought about those? OS/2 file system is based on drives[A-Z]. '/' means a root of a current drive. There are maximum 26 kinds of '/'. For examples, consider that xxx is installed into f:/usr/bin. If executing xxx on drive e:, '/' of xxx is e:/ not f:/. In this case, xxx fails to find its root. $UNIXROOT is used to overcome this problem. On OS/2, $UNIXROOT is used to specify a drive of '/'. And all programs following FHS are installed on a drive specified by $UNIXROOT. In the above, if UNIXROOT is set to 'f:'. Then '/' is translated to 'f:/' as xxx expects. And see http://trac.netlabs.org/libc/wiki/UnixPenthouseApartement. Still not assured ? -- KO Myung-Hun Using Mozilla SeaMonkey 2.7.2 Under OS/2 Warp 4 for Korean with FixPak #15 In VirtualBox v4.1.32 on Intel Core i7-3615QM 2.30GHz with 8GB RAM Korean OS/2 User Community : http://www.ecomstation.co.kr
Re: [PATCH 03/14] relocatable: support UNIXROOT in relocate() on EMX
On Tue, Dec 09, 2014 at 02:51:51PM +0900, KO Myung-Hun wrote: Ben Pfaff wrote: On Tue, Dec 09, 2014 at 10:40:48AM +0900, KO Myung-Hun wrote: UNIXROOT is used to specify a drive of a root of FHS. So if a path is started with '/', then it should be translated to $UNIXROOT/. * lib/relocatable.c (relocate): Prepend $UNIXROOT to pathname if it is started with '/' on EMX. As one of the maintainers of the relocatable modules, the code in this patch seems reasonable to me. I don't know enough about OS/2 or EMX to know whether $UNIXROOT is a customary variable or whether this is a correct context for using it. Can you assure me that you've thought about those? OS/2 file system is based on drives[A-Z]. '/' means a root of a current drive. There are maximum 26 kinds of '/'. For examples, consider that xxx is installed into f:/usr/bin. If executing xxx on drive e:, '/' of xxx is e:/ not f:/. In this case, xxx fails to find its root. $UNIXROOT is used to overcome this problem. On OS/2, $UNIXROOT is used to specify a drive of '/'. And all programs following FHS are installed on a drive specified by $UNIXROOT. In the above, if UNIXROOT is set to 'f:'. Then '/' is translated to 'f:/' as xxx expects. And see http://trac.netlabs.org/libc/wiki/UnixPenthouseApartement. Still not assured ? Thank you for explaining. I applied this to the gnulib repository. Thanks, Ben.
Re: [PATCH 03/14] relocatable: support UNIXROOT in relocate() on EMX
Ben Pfaff wrote: On Tue, Dec 09, 2014 at 02:51:51PM +0900, KO Myung-Hun wrote: Ben Pfaff wrote: On Tue, Dec 09, 2014 at 10:40:48AM +0900, KO Myung-Hun wrote: UNIXROOT is used to specify a drive of a root of FHS. So if a path is started with '/', then it should be translated to $UNIXROOT/. * lib/relocatable.c (relocate): Prepend $UNIXROOT to pathname if it is started with '/' on EMX. As one of the maintainers of the relocatable modules, the code in this patch seems reasonable to me. I don't know enough about OS/2 or EMX to know whether $UNIXROOT is a customary variable or whether this is a correct context for using it. Can you assure me that you've thought about those? OS/2 file system is based on drives[A-Z]. '/' means a root of a current drive. There are maximum 26 kinds of '/'. For examples, consider that xxx is installed into f:/usr/bin. If executing xxx on drive e:, '/' of xxx is e:/ not f:/. In this case, xxx fails to find its root. $UNIXROOT is used to overcome this problem. On OS/2, $UNIXROOT is used to specify a drive of '/'. And all programs following FHS are installed on a drive specified by $UNIXROOT. In the above, if UNIXROOT is set to 'f:'. Then '/' is translated to 'f:/' as xxx expects. And see http://trac.netlabs.org/libc/wiki/UnixPenthouseApartement. Still not assured ? Thank you for explaining. I applied this to the gnulib repository. Thanks a lot for applying promptly. -- KO Myung-Hun Using Mozilla SeaMonkey 2.7.2 Under OS/2 Warp 4 for Korean with FixPak #15 In VirtualBox v4.1.32 on Intel Core i7-3615QM 2.30GHz with 8GB RAM Korean OS/2 User Community : http://www.ecomstation.co.kr