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.
#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
return n_groups;
}
+
+#endif /* HAVE_GETGROUPS */
#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.
return count;
}
+
+#endif /* HAVE_GRP_H */
#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.
-# serial 12
+# serial 13
dnl From Jim Meyering.
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])
-])
-# 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.
AC_DEFUN([gl_GETUGROUPS],
[
AC_LIBOBJ([getugroups])
+ AC_CHECK_HEADERS_ONCE([grp.h])
dnl Prerequisites of lib/getugroups.c.
AC_TYPE_GETGROUPS
-# 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,
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])
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])
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])
configure.ac:
gl_FUNC_GETGROUPS
+gl_UNISTD_MODULE_INDICATOR([getgroups])
Makefile.am:
-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' \
-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' \
-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' \