Mercurial > hg > octave-nkf > gnulib-hg
changeset 12279:6a41b8f5f874
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>
author | Eric Blake <ebb9@byu.net> |
---|---|
date | Thu, 12 Nov 2009 09:53:14 -0700 |
parents | 0a3dcff9559e |
children | 39be377f1765 |
files | 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 |
diffstat | 9 files changed, 90 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- 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.
--- 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 @@ return n_groups; } + +#endif /* HAVE_GETGROUPS */
--- 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 + +/* Mingw lacks all things related to group management. The best we + can do is fail with ENOSYS. */ -/* 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); +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; +} -#include <string.h> +#else /* HAVE_GRP_H */ +# include <grp.h> -#define STREQ(s1, s2) (strcmp (s1, s2) == 0) +# 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 @@ return count; } + +#endif /* HAVE_GRP_H */
--- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -406,6 +406,28 @@ #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.
--- a/m4/getgroups.m4 +++ b/m4/getgroups.m4 @@ -1,4 +1,4 @@ -# serial 12 +# serial 13 dnl From Jim Meyering. dnl A wrapper around AC_FUNC_GETGROUPS. @@ -12,17 +12,14 @@ 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]) - AC_DEFINE([getgroups], [rpl_getgroups], - [Define as rpl_getgroups if getgroups doesn't work right.]) - gl_PREREQ_GETGROUPS + HAVE_GETGROUPS=0 + elif test "$ac_cv_func_getgroups_works" != yes; then + AC_LIBOBJ([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]) -])
--- a/m4/getugroups.m4 +++ b/m4/getugroups.m4 @@ -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 @@ AC_DEFUN([gl_GETUGROUPS], [ AC_LIBOBJ([getugroups]) + AC_CHECK_HEADERS_ONCE([grp.h]) dnl Prerequisites of lib/getugroups.c. AC_TYPE_GETGROUPS
--- a/m4/unistd_h.m4 +++ b/m4/unistd_h.m4 @@ -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 @@ 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 @@ 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 @@ 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])
--- a/modules/getgroups +++ b/modules/getgroups @@ -11,6 +11,7 @@ configure.ac: gl_FUNC_GETGROUPS +gl_UNISTD_MODULE_INDICATOR([getgroups]) Makefile.am:
--- a/modules/unistd +++ b/modules/unistd @@ -39,6 +39,7 @@ -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 @@ -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 @@ -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' \