Patchwork [libfortran] PR 47802 Non-POSIX getpwuid_r

login
register
mail settings
Submitter Janne Blomqvist
Date Feb. 22, 2011, 8:22 p.m.
Message ID <AANLkTinsiz86LrOUvc5NjjfeMyftfsO_VFHDn1L3Tr_T@mail.gmail.com>
Download mbox | patch
Permalink /patch/84001/
State New
Headers show

Comments

Janne Blomqvist - Feb. 22, 2011, 8:22 p.m.
Hi,

the attached patch fixes the second part of the bootstrap failure on
HP-UX 10.2. That target provides a non-POSIX getpwuid_r function which
has one argument less than the POSIX version. The patch adds a
configure test for this.

Regtested on x86_64-unknown-linux-gnu, Ok for trunk?

2011-02-22  Janne Blomqvist  <jb@gcc.gnu.org>

	PR libfortran/47802
	* configure.ac: Add test for POSIX getpwuid_r.
	* intrinsics/getlog.c (getlog): CPP test for
	HAVE_POSIX_GETPWUID_R.
	* config.h.in: Regenerated.
	* configure: Regenerated.
Ralf Wildenhues - Feb. 23, 2011, 6:13 p.m.
* Janne Blomqvist wrote on Tue, Feb 22, 2011 at 09:22:14PM CET:
> Regtested on x86_64-unknown-linux-gnu, Ok for trunk?
> 
> 2011-02-22  Janne Blomqvist  <jb@gcc.gnu.org>
> 
> 	PR libfortran/47802
> 	* configure.ac: Add test for POSIX getpwuid_r.
> 	* intrinsics/getlog.c (getlog): CPP test for
> 	HAVE_POSIX_GETPWUID_R.
> 	* config.h.in: Regenerated.
> 	* configure: Regenerated.

> --- a/libgfortran/configure.ac
> +++ b/libgfortran/configure.ac
> @@ -513,6 +513,28 @@ AC_SUBST(FPU_HOST_HEADER)
>  IEEE_FLAGS="${ieee_flags}"
>  AC_SUBST(IEEE_FLAGS)
>  
> +
> +# Check for POSIX getpwuid_r 
> +#
> +# There are two versions of getpwuid_r, the POSIX one with 5
> +# arguments, and another one with 4 arguments used by at least HP-UX
> +# 10.2.
> +if test "$ac_cv_func_getpwuid_r" = "yes"; then
> +AC_CACHE_CHECK([POSIX version of getpwuid_r with 5 arguments], libgfor_cv_posix_getpwuid_r, [
> +AC_TRY_LINK([
> +#include <stdio.h>
> +#include <sys/types.h>
> +#include <pwd.h>], [
> +    getpwuid_r(0, NULL, NULL, 0, NULL);
> +],  [libgfor_cv_posix_getpwuid_r="yes"], [libgfor_cv_posix_getpwuid_r="no"])])
> +fi
> +if test "$libgfor_cv_posix_getpwuid_r" = "yes"; then
> +    AC_DEFINE(HAVE_POSIX_GETPWUID_R)
> +    AH_TEMPLATE(HAVE_POSIX_GETPWUID_R,
> +        [Define to 1 if we have POSIX getpwuid_r which takes 5 arguments.])
> +fi
> +
> +

Build system parts are OK.  You /could/ indent the AC_CACHE_CHCEK and
following line, use AC_LINK_IFELSE instead of AC_TRY_LINK, and use the
three-argument form of AC_DEFINE instead of adding the AH_TEMPLATE, but
all of that are janitorial issues just as well suitable for stage 1
cleanup.

Thanks,
Ralf

Patch

diff --git a/libgfortran/configure.ac b/libgfortran/configure.ac
index 8161659..b839ae0 100644
--- a/libgfortran/configure.ac
+++ b/libgfortran/configure.ac
@@ -513,6 +513,28 @@  AC_SUBST(FPU_HOST_HEADER)
 IEEE_FLAGS="${ieee_flags}"
 AC_SUBST(IEEE_FLAGS)
 
+
+# Check for POSIX getpwuid_r 
+#
+# There are two versions of getpwuid_r, the POSIX one with 5
+# arguments, and another one with 4 arguments used by at least HP-UX
+# 10.2.
+if test "$ac_cv_func_getpwuid_r" = "yes"; then
+AC_CACHE_CHECK([POSIX version of getpwuid_r with 5 arguments], libgfor_cv_posix_getpwuid_r, [
+AC_TRY_LINK([
+#include <stdio.h>
+#include <sys/types.h>
+#include <pwd.h>], [
+    getpwuid_r(0, NULL, NULL, 0, NULL);
+],  [libgfor_cv_posix_getpwuid_r="yes"], [libgfor_cv_posix_getpwuid_r="no"])])
+fi
+if test "$libgfor_cv_posix_getpwuid_r" = "yes"; then
+    AC_DEFINE(HAVE_POSIX_GETPWUID_R)
+    AH_TEMPLATE(HAVE_POSIX_GETPWUID_R,
+        [Define to 1 if we have POSIX getpwuid_r which takes 5 arguments.])
+fi
+
+
 # Check out attribute support.
 LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY
 LIBGFOR_CHECK_ATTRIBUTE_DLLEXPORT
diff --git a/libgfortran/intrinsics/getlog.c b/libgfortran/intrinsics/getlog.c
index 299ac5a..9e5c8de 100644
--- a/libgfortran/intrinsics/getlog.c
+++ b/libgfortran/intrinsics/getlog.c
@@ -75,7 +75,7 @@  PREFIX(getlog) (char * login, gfc_charlen_type login_len)
 
   memset (login, ' ', login_len); /* Blank the string.  */
 
-#if defined(HAVE_GETPWUID_R) && defined(HAVE_GETEUID)
+#if defined(HAVE_POSIX_GETPWUID_R) && defined(HAVE_GETEUID)
   struct passwd pwd;
   struct passwd *result;
   char *buf;
@@ -113,7 +113,7 @@  PREFIX(getlog) (char * login, gfc_charlen_type login_len)
   memcpy (login, p, p_len);
 
  cleanup:
-#ifdef HAVE_GETPWUID_R
+#if defined (HAVE_POSIX_GETPWUID_R) && defined(HAVE_GETEUID)
   free (buf);
 #else
   ;