summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEric Blake <ebb9@byu.net>2009-11-12 09:53:14 -0700
committerEric Blake <ebb9@byu.net>2009-11-13 07:39:24 -0700
commit61b3a42219dc8f575923346b59162f81186b7425 (patch)
tree6d3ec84212b897f71fa0df89498ca1281fabada6 /lib
parent80074d103cc72ea8f289b82c56bd3734aac82cd7 (diff)
downloadgnulib-61b3a42219dc8f575923346b59162f81186b7425.tar.gz
getgroups, getugroups: provide stubs for mingw
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>
Diffstat (limited to 'lib')
-rw-r--r--lib/getgroups.c17
-rw-r--r--lib/getugroups.c29
-rw-r--r--lib/unistd.in.h22
3 files changed, 58 insertions, 10 deletions
diff --git a/lib/getgroups.c b/lib/getgroups.c
index e764d732fc..bad676ea5e 100644
--- a/lib/getgroups.c
+++ b/lib/getgroups.c
@@ -25,7 +25,20 @@
#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 */
diff --git a/lib/getugroups.c b/lib/getugroups.c
index 2207b85a17..a614ec7be3 100644
--- a/lib/getugroups.c
+++ b/lib/getugroups.c
@@ -21,22 +21,31 @@
#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 */
diff --git a/lib/unistd.in.h b/lib/unistd.in.h
index b6d2fa06b8..90494e4d1d 100644
--- a/lib/unistd.in.h
+++ b/lib/unistd.in.h
@@ -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.