getgroups, getugroups: provide stubs for mingw
authorEric Blake <ebb9@byu.net>
Thu, 12 Nov 2009 16:53:14 +0000 (09:53 -0700)
committerEric Blake <ebb9@byu.net>
Fri, 13 Nov 2009 14:39:24 +0000 (07:39 -0700)
Avoid link failure on mingw, which lacks getgroups and anything
else related to gid_t management (stat.st_gid is always 0).

* lib/getgroups.c (getgroups): Provide ENOSYS stub for mingw.
* lib/getugroups.c (getugroups): Likewise.
* m4/getgroups.m4 (gl_FUNC_GETGROUPS): Check for missing
function.  Modernize replacement scheme.
(gl_PREREQ_GETGROUPS): Delete.
* m4/getugroups.m4 (gl_GETUGROUPS): Check for <grp.h>.
* modules/getgroups (configure.ac): Declare witness.
* m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Add default.
* modules/unistd (Depends-on): Substitute witness.
* lib/unistd.in.h (getgroups): Declare replacement.

Signed-off-by: Eric Blake <ebb9@byu.net>
ChangeLog
lib/getgroups.c
lib/getugroups.c
lib/unistd.in.h
m4/getgroups.m4
m4/getugroups.m4
m4/unistd_h.m4
modules/getgroups
modules/unistd

index 86e3bf8..26aa643 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2009-11-13  Eric Blake  <ebb9@byu.net>
 
+       getgroups, getugroups: provide stubs for mingw
+       * lib/getgroups.c (getgroups): Provide ENOSYS stub for mingw.
+       * lib/getugroups.c (getugroups): Likewise.
+       * m4/getgroups.m4 (gl_FUNC_GETGROUPS): Check for missing
+       function.  Modernize replacement scheme.
+       (gl_PREREQ_GETGROUPS): Delete.
+       * m4/getugroups.m4 (gl_GETUGROUPS): Check for <grp.h>.
+       * modules/getgroups (configure.ac): Declare witness.
+       * m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Add default.
+       * modules/unistd (Depends-on): Substitute witness.
+       * lib/unistd.in.h (getgroups): Declare replacement.
+
        getgroups: avoid calling exit
        * modules/getgroups (Depends-on): Add malloc-posix and unistd,
        drop xalloc.
index e764d73..bad676e 100644 (file)
 #include <errno.h>
 #include <stdlib.h>
 
-#undef getgroups
+#if !HAVE_GETGROUPS
+
+/* Provide a stub that fails with ENOSYS, since there is no group
+   information available on mingw.  */
+int
+getgroups (int n _UNUSED_PARAMETER_, GETGROUPS_T *groups _UNUSED_PARAMETER_)
+{
+  errno = ENOSYS;
+  return -1;
+}
+
+#else /* HAVE_GETGROUPS */
+
+# undef getgroups
 
 /* On at least Ultrix 4.3 and NextStep 3.2, getgroups (0, NULL) always
    fails.  On other systems, it returns the number of supplemental
@@ -66,3 +79,5 @@ rpl_getgroups (int n, GETGROUPS_T *group)
 
   return n_groups;
 }
+
+#endif /* HAVE_GETGROUPS */
index 2207b85..a614ec7 100644 (file)
 
 #include "getugroups.h"
 
+#include <errno.h>
 #include <limits.h>
 #include <stdio.h> /* grp.h on alpha OSF1 V2.0 uses "FILE *". */
-#include <grp.h>
-
+#include <string.h>
 #include <unistd.h>
 
-#include <errno.h>
+#if !HAVE_GRP_H
 
-/* Some old header files might not declare setgrent, getgrent, and endgrent.
-   If you don't have them at all, we can't implement this function.
-   You lose!  */
-struct group *getgrent (void);
+/* Mingw lacks all things related to group management.  The best we
+   can do is fail with ENOSYS.  */
 
-#include <string.h>
+int
+getugroups (int maxcount _UNUSED_PARAMETER_,
+            gid_t *grouplist _UNUSED_PARAMETER_,
+            char const *username _UNUSED_PARAMETER_,
+            gid_t gid _UNUSED_PARAMETER_)
+{
+  errno = ENOSYS;
+  return -1;
+}
 
-#define STREQ(s1, s2) (strcmp (s1, s2) == 0)
+#else /* HAVE_GRP_H */
+# include <grp.h>
+
+# define STREQ(s1, s2) (strcmp (s1, s2) == 0)
 
 /* Like `getgroups', but for user USERNAME instead of for the current
    process.  Store at most MAXCOUNT group IDs in the GROUPLIST array.
@@ -112,3 +121,5 @@ getugroups (int maxcount, GETGROUPS_T *grouplist, char const *username,
 
   return count;
 }
+
+#endif /* HAVE_GRP_H */
index b6d2fa0..90494e4 100644 (file)
@@ -406,6 +406,28 @@ extern int getdtablesize (void);
 #endif
 
 
+#if @GNULIB_GETGROUPS@
+# if @REPLACE_GETGROUPS@
+#  undef getgroups
+#  define getgroups rpl_getgroups
+# endif
+# if !@HAVE_GETGROUPS@ || @REPLACE_GETGROUPS@
+/* Return the supplemental groups that the current process belongs to.
+   It is unspecified whether the effective group id is in the list.
+   If N is 0, return the group count; otherwise, N describes how many
+   entries are available in GROUPS.  Return -1 and set errno if N is
+   not 0 and not large enough.  Fails with ENOSYS on some systems.  */
+int getgroups (int n, GETGROUPS_T *groups);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef getgroups
+# define getgroups(n,g)                                                 \
+    (GL_LINK_WARNING ("getgroups is unportable - "                      \
+                      "use gnulib module getgroups for portability"),   \
+     getgroups (n, g))
+#endif
+
+
 #if @GNULIB_GETHOSTNAME@
 /* Return the standard host name of the machine.
    WARNING! The host name may or may not be fully qualified.
index a7019fb..1dd39ea 100644 (file)
@@ -1,4 +1,4 @@
-# serial 12
+# serial 13
 
 dnl From Jim Meyering.
 dnl A wrapper around AC_FUNC_GETGROUPS.
@@ -12,17 +12,14 @@ dnl A wrapper around AC_FUNC_GETGROUPS.
 AC_DEFUN([gl_FUNC_GETGROUPS],
 [
   AC_REQUIRE([AC_FUNC_GETGROUPS])
-  if test "$ac_cv_func_getgroups_works" != yes; then
+  AC_REQUIRE([AC_TYPE_GETGROUPS])
+  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+  if test "$ac_cv_func_getgroups" != yes; then
+    AC_LIBOBJ([getgroups])
+    HAVE_GETGROUPS=0
+  elif test "$ac_cv_func_getgroups_works" != yes; then
     AC_LIBOBJ([getgroups])
-    AC_DEFINE([getgroups], [rpl_getgroups],
-      [Define as rpl_getgroups if getgroups doesn't work right.])
-    gl_PREREQ_GETGROUPS
+    REPLACE_GETGROUPS=1
   fi
   test -n "$GETGROUPS_LIB" && LIBS="$GETGROUPS_LIB $LIBS"
 ])
-
-# Prerequisites of lib/getgroups.c.
-AC_DEFUN([gl_PREREQ_GETGROUPS],
-[
-  AC_REQUIRE([AC_TYPE_GETGROUPS])
-])
index 3c5e15e..e437e1b 100644 (file)
@@ -1,5 +1,6 @@
-# getugroups.m4 serial 6
-dnl Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc.
+# getugroups.m4 serial 7
+dnl Copyright (C) 2002, 2003, 2005, 2006, 2009 Free Software
+dnl Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
@@ -7,6 +8,7 @@ dnl with or without modifications, as long as this notice is preserved.
 AC_DEFUN([gl_GETUGROUPS],
 [
   AC_LIBOBJ([getugroups])
+  AC_CHECK_HEADERS_ONCE([grp.h])
 
   dnl Prerequisites of lib/getugroups.c.
   AC_TYPE_GETGROUPS
index 5aa39ae..5c94916 100644 (file)
@@ -1,4 +1,4 @@
-# unistd_h.m4 serial 31
+# unistd_h.m4 serial 32
 dnl Copyright (C) 2006-2009 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -46,6 +46,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
   GNULIB_GETCWD=0;           AC_SUBST([GNULIB_GETCWD])
   GNULIB_GETDOMAINNAME=0;    AC_SUBST([GNULIB_GETDOMAINNAME])
   GNULIB_GETDTABLESIZE=0;    AC_SUBST([GNULIB_GETDTABLESIZE])
+  GNULIB_GETGROUPS=0;        AC_SUBST([GNULIB_GETGROUPS])
   GNULIB_GETHOSTNAME=0;      AC_SUBST([GNULIB_GETHOSTNAME])
   GNULIB_GETLOGIN_R=0;       AC_SUBST([GNULIB_GETLOGIN_R])
   GNULIB_GETPAGESIZE=0;      AC_SUBST([GNULIB_GETPAGESIZE])
@@ -76,6 +77,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
   HAVE_FTRUNCATE=1;       AC_SUBST([HAVE_FTRUNCATE])
   HAVE_GETDOMAINNAME=1;   AC_SUBST([HAVE_GETDOMAINNAME])
   HAVE_GETDTABLESIZE=1;   AC_SUBST([HAVE_GETDTABLESIZE])
+  HAVE_GETGROUPS=1;       AC_SUBST([HAVE_GETGROUPS])
   HAVE_GETHOSTNAME=1;     AC_SUBST([HAVE_GETHOSTNAME])
   HAVE_GETPAGESIZE=1;     AC_SUBST([HAVE_GETPAGESIZE])
   HAVE_GETUSERSHELL=1;    AC_SUBST([HAVE_GETUSERSHELL])
@@ -99,6 +101,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
   REPLACE_FCHDIR=0;       AC_SUBST([REPLACE_FCHDIR])
   REPLACE_FCHOWNAT=0;     AC_SUBST([REPLACE_FCHOWNAT])
   REPLACE_GETCWD=0;       AC_SUBST([REPLACE_GETCWD])
+  REPLACE_GETGROUPS=0;    AC_SUBST([REPLACE_GETGROUPS])
   REPLACE_GETPAGESIZE=0;  AC_SUBST([REPLACE_GETPAGESIZE])
   REPLACE_LCHOWN=0;       AC_SUBST([REPLACE_LCHOWN])
   REPLACE_LINK=0;         AC_SUBST([REPLACE_LINK])
index 472d20e..8ecbbdd 100644 (file)
@@ -11,6 +11,7 @@ unistd
 
 configure.ac:
 gl_FUNC_GETGROUPS
+gl_UNISTD_MODULE_INDICATOR([getgroups])
 
 Makefile.am:
 
index d299e4a..48259ac 100644 (file)
@@ -39,6 +39,7 @@ unistd.h: unistd.in.h
              -e 's|@''GNULIB_GETCWD''@|$(GNULIB_GETCWD)|g' \
              -e 's|@''GNULIB_GETDOMAINNAME''@|$(GNULIB_GETDOMAINNAME)|g' \
              -e 's|@''GNULIB_GETDTABLESIZE''@|$(GNULIB_GETDTABLESIZE)|g' \
+             -e 's|@''GNULIB_GETGROUPS''@|$(GNULIB_GETGROUPS)|g' \
              -e 's|@''GNULIB_GETHOSTNAME''@|$(GNULIB_GETHOSTNAME)|g' \
              -e 's|@''GNULIB_GETLOGIN_R''@|$(GNULIB_GETLOGIN_R)|g' \
              -e 's|@''GNULIB_GETPAGESIZE''@|$(GNULIB_GETPAGESIZE)|g' \
@@ -68,6 +69,7 @@ unistd.h: unistd.in.h
              -e 's|@''HAVE_FTRUNCATE''@|$(HAVE_FTRUNCATE)|g' \
              -e 's|@''HAVE_GETDOMAINNAME''@|$(HAVE_GETDOMAINNAME)|g' \
              -e 's|@''HAVE_GETDTABLESIZE''@|$(HAVE_GETDTABLESIZE)|g' \
+             -e 's|@''HAVE_GETGROUPS''@|$(HAVE_GETGROUPS)|g' \
              -e 's|@''HAVE_GETHOSTNAME''@|$(HAVE_GETHOSTNAME)|g' \
              -e 's|@''HAVE_GETPAGESIZE''@|$(HAVE_GETPAGESIZE)|g' \
              -e 's|@''HAVE_GETUSERSHELL''@|$(HAVE_GETUSERSHELL)|g' \
@@ -91,6 +93,7 @@ unistd.h: unistd.in.h
              -e 's|@''REPLACE_FCHDIR''@|$(REPLACE_FCHDIR)|g' \
              -e 's|@''REPLACE_FCHOWNAT''@|$(REPLACE_FCHOWNAT)|g' \
              -e 's|@''REPLACE_GETCWD''@|$(REPLACE_GETCWD)|g' \
+             -e 's|@''REPLACE_GETGROUPS''@|$(REPLACE_GETGROUPS)|g' \
              -e 's|@''REPLACE_GETPAGESIZE''@|$(REPLACE_GETPAGESIZE)|g' \
              -e 's|@''REPLACE_LCHOWN''@|$(REPLACE_LCHOWN)|g' \
              -e 's|@''REPLACE_LINK''@|$(REPLACE_LINK)|g' \