hash, mgetgroups: drop xalloc dependency
authorEric Blake <eblake@redhat.com>
Wed, 27 Apr 2011 22:23:45 +0000 (16:23 -0600)
committerEric Blake <eblake@redhat.com>
Thu, 28 Apr 2011 20:22:07 +0000 (14:22 -0600)
Rely on the new xalloc-oversized module to avoid requiring
xalloc-die for functions documented as returning NULL on
potential allocation overflow.

* lib/hash.c (includes): Adjust includes.
* lib/mgetgroups.c (includes): Likewise.
(xgetgroups): Move...
* lib/xgetgroups.c: ...to new file.
* modules/xgetgroups: New file, split from...
* modules/mgetgroups: ...here.
(Depends-on): Add xalloc-oversized.
* modules/hash (Depends-on): Likewise.
* modules/hash-tests (Depends-on): Drop xalloc.
(test_hash_LDADD): Drop unused library.
* tests/test-hash.c (main): Break xalloc dependency.
(includes): Drop unused include.

Signed-off-by: Eric Blake <eblake@redhat.com>
ChangeLog
NEWS
lib/hash.c
lib/mgetgroups.c
lib/mgetgroups.h
lib/xgetgroups.c [new file with mode: 0644]
modules/hash
modules/hash-tests
modules/mgetgroups
modules/xgetgroups [new file with mode: 0644]
tests/test-hash.c

index 039d3c55b6c4710ee7386c46299212d808a4cdca..df91f2583dd86480ff066d897bbc3731da069809 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
 2011-04-28  Eric Blake  <eblake@redhat.com>
 
+       hash, mgetgroups: drop xalloc dependency
+       * lib/hash.c (includes): Adjust includes.
+       * lib/mgetgroups.c (includes): Likewise.
+       (xgetgroups): Move...
+       * lib/xgetgroups.c: ...to new file.
+       * lib/mgetgroups.h (xgetgroups): Make declaration conditional.
+       * modules/xgetgroups: New file, split from...
+       * modules/mgetgroups: ...here.
+       (Depends-on): Add xalloc-oversized.
+       * modules/hash (Depends-on): Likewise.
+       * modules/hash-tests (Depends-on): Drop xalloc.
+       (test_hash_LDADD): Drop unused library.
+       * tests/test-hash.c (main): Break xalloc dependency.
+       (includes): Drop unused include.
+
        xalloc-oversized: new module
        * modules/xalloc-oversized: New module.
        * modules/xalloc (Depends-on): Add it.
diff --git a/NEWS b/NEWS
index 5081dbaa8208da3c8eb4133d2c490a154e7904ee..b693a33596723c942683c57a9e30a0fa23415858 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,9 @@ User visible incompatible changes
 
 Date        Modules         Changes
 
+2011-04-27  mgetgroups      The 'xgetgroups' function has been split into
+                            a new 'xgetgroups' module.
+
 2011-04-27  save-cwd        This module pulls in fewer dependencies by
                             default; to retain robust handling of directories
                             with an absolute name longer than PATH_MAX, you
index f3de2aaaace2420e353691ccbeb45e5784528a1f..4d76f765e90b4ba549ce097b8eb717a6cb869e2b 100644 (file)
@@ -27,7 +27,7 @@
 #include "hash.h"
 
 #include "bitrotate.h"
-#include "xalloc.h"
+#include "xalloc-oversized.h"
 
 #include <stdint.h>
 #include <stdio.h>
index 5c79915bcc314e6adab6ec0165503c2c0be88118..e0aa250ca44daf5bfa9eb95ddc3c4e0619a7fead 100644 (file)
@@ -31,7 +31,7 @@
 #endif
 
 #include "getugroups.h"
-#include "xalloc.h"
+#include "xalloc-oversized.h"
 
 static gid_t *
 realloc_groupbuf (gid_t *g, size_t num)
@@ -193,14 +193,3 @@ mgetgroups (char const *username, gid_t gid, gid_t **groups)
 
   return ng;
 }
-
-/* Like mgetgroups, but call xalloc_die on allocation failure.  */
-
-int
-xgetgroups (char const *username, gid_t gid, gid_t **groups)
-{
-  int result = mgetgroups (username, gid, groups);
-  if (result == -1 && errno == ENOMEM)
-    xalloc_die ();
-  return result;
-}
index a1fd040e7348b20bf09b489ea30b88be1d36a6e7..7a572bc2f7844a24237960a04d6d5a4d08376117 100644 (file)
@@ -17,4 +17,6 @@
 #include <sys/types.h>
 
 int mgetgroups (const char *username, gid_t gid, gid_t **groups);
+#if GNULIB_XGETGROUPS
 int xgetgroups (const char *username, gid_t gid, gid_t **groups);
+#endif
diff --git a/lib/xgetgroups.c b/lib/xgetgroups.c
new file mode 100644 (file)
index 0000000..41886c9
--- /dev/null
@@ -0,0 +1,37 @@
+/* xgetgroups.c -- return a list of the groups a user or current process is in
+
+   Copyright (C) 2007-2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Extracted from coreutils' src/id.c. */
+
+#include <config.h>
+
+#include "mgetgroups.h"
+
+#include <errno.h>
+
+#include "xalloc.h"
+
+/* Like mgetgroups, but call xalloc_die on allocation failure.  */
+
+int
+xgetgroups (char const *username, gid_t gid, gid_t **groups)
+{
+  int result = mgetgroups (username, gid, groups);
+  if (result == -1 && errno == ENOMEM)
+    xalloc_die ();
+  return result;
+}
index 75a99da3735c9ef4817d8af47bb22a125f1e5dd4..72afda6cf1f76751964eef8fd557f8ef72caba56 100644 (file)
@@ -1,5 +1,5 @@
 Description:
-Parametrizable hash table.
+Parameterizable hash table.
 
 Files:
 lib/hash.c
@@ -10,7 +10,7 @@ Depends-on:
 bitrotate
 stdbool
 stdint
-xalloc
+xalloc-oversized
 
 configure.ac:
 gl_HASH
index a77bfe7d68e546de5a9a3b548dc551a2483fb74e..b3f814b6ec1cc29271eba79171f9e8b7a02b7902 100644 (file)
@@ -7,11 +7,9 @@ hash-pjw
 inttostr
 progname
 stdbool
-xalloc
 
 configure.ac:
 
 Makefile.am:
 TESTS += test-hash
 check_PROGRAMS += test-hash
-test_hash_LDADD = $(LDADD) @LIBINTL@
index c404d0143570833e4002d9d9376f417c3132fb02..1aa1c79ae69c2b656c453a33db54833fd62e3d1f 100644 (file)
@@ -10,7 +10,7 @@ Depends-on:
 getgroups
 getugroups
 realloc-gnu
-xalloc
+xalloc-oversized
 
 configure.ac:
 gl_MGETGROUPS
diff --git a/modules/xgetgroups b/modules/xgetgroups
new file mode 100644 (file)
index 0000000..6ae3614
--- /dev/null
@@ -0,0 +1,25 @@
+Description:
+Return the group IDs of a user or current process in malloc'd storage, with
+out-of-memory checking.
+
+Files:
+lib/xgetgroups.c
+
+Depends-on:
+mgetgroups
+xalloc
+
+configure.ac:
+gl_MODULE_INDICATOR([xgetgroups])
+
+Makefile.am:
+lib_SOURCES += xgetgroups.c
+
+Include:
+"mgetgroups.h"
+
+License:
+GPL
+
+Maintainer:
+Jim Meyering, Eric Blake
index 108daefdf47c13bf779631f5cddcd91d8a9f3a60..ecfe357ccdf161d485e722db87ace67b6d68c4b8 100644 (file)
@@ -20,7 +20,6 @@
 #include "hash.h"
 #include "hash-pjw.h"
 #include "inttostr.h"
-#include "xalloc.h"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -114,8 +113,10 @@ main (int argc, char **argv)
       ASSERT (ht);
       insert_new (ht, "a");
       {
-        char *str1 = xstrdup ("a");
-        char *str2 = hash_insert (ht, str1);
+        char *str1 = strdup ("a");
+        char *str2;
+        ASSERT (str1);
+        str2 = hash_insert (ht, str1);
         ASSERT (str1 != str2);
         ASSERT (STREQ (str1, str2));
         free (str1);
@@ -161,7 +162,8 @@ main (int argc, char **argv)
       ht = hash_initialize (sz, NULL, NULL, NULL, NULL);
       ASSERT (ht);
       {
-        char *str = xstrdup ("a");
+        char *str = strdup ("a");
+        ASSERT (str);
         insert_new (ht, "a");
         insert_new (ht, str);
         ASSERT (hash_lookup (ht, str) == str);
@@ -206,7 +208,9 @@ main (int argc, char **argv)
               {
                 char buf[50];
                 char const *p = uinttostr (i, buf);
-                insert_new (ht, xstrdup (p));
+                char *dup = strdup (p);
+                ASSERT (dup);
+                insert_new (ht, dup);
               }
               break;