I'm wondering if there's a reason why the 'inttostr' module
shouldn't support the conversion from uid_t and gid_t to char*,
 i.e., why there are no uidtostr() and gidtostr() functions.

Just in case - the attached patch would add them ...

Have a nice day,
Berny

>From e737d10b6679b07db28d8868aa633bd45dd268a6 Mon Sep 17 00:00:00 2001
From: Bernhard Voelker <m...@bernhard-voelker.de>
Date: Mon, 12 Aug 2013 00:24:40 +0200
Subject: [PATCH] inttostr: add gidtostr and uidtostr

* build-aux/prefix-gnulib-mk (lib_libcoreutils_a_SOURCES): Add
gidtostr and uidtostr to the pattern.
* lib/inttostr.h: Add declarations for gidtostr() and uidtostr().
* lib/gidtostr.c: Add new source to define gidtostr for use
with the gid_t type.
* lib/uidtostr.c: Add new source to define uidtostr for use
with the uid_t type.
* lib/userspec.c (parse_with_separator): Use new gidtostr instead
of umaxtostr for the GID conversion.
* m4/inttostr.m4 (gl_INTTOSTR): Add gl_PREREQ_GIDTOSTR and
gl_PREREQ_UIDTOSTR and define them.
* modules/inttostr: Add gidtostr.c and uidtostr.c to Files list.
(lib_SOURCES): Also add them here.
* tests/test-inttostr.c (main): Add a test for gidtostr/uidtostr.
* top/maint.mk (sc_prohibit_inttostr_without_use): Add gidtostr
and uidtostr to the pattern.
---
 ChangeLog                  | 20 ++++++++++++++++++++
 build-aux/prefix-gnulib-mk |  4 +++-
 lib/gidtostr.c             |  3 +++
 lib/inttostr.h             |  2 ++
 lib/uidtostr.c             |  3 +++
 lib/userspec.c             |  2 +-
 m4/inttostr.m4             |  8 ++++++++
 modules/inttostr           |  4 ++++
 tests/test-inttostr.c      |  2 ++
 top/maint.mk               |  2 +-
 10 files changed, 47 insertions(+), 3 deletions(-)
 create mode 100644 lib/gidtostr.c
 create mode 100644 lib/uidtostr.c

diff --git a/ChangeLog b/ChangeLog
index b850fb6..d68db70 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2013-08-12  Bernhard Voelker  <m...@bernhard-voelker.de>
+
+	inttostr: add gidtostr and uidtostr
+	* build-aux/prefix-gnulib-mk (lib_libcoreutils_a_SOURCES): Add
+	gidtostr and uidtostr to the pattern.
+	* lib/inttostr.h: Add declarations for gidtostr() and uidtostr().
+	* lib/gidtostr.c: Add new source to define gidtostr for use
+	with the gid_t type.
+	* lib/uidtostr.c: Add new source to define uidtostr for use
+	with the uid_t type.
+	* lib/userspec.c (parse_with_separator): Use new gidtostr instead
+	of umaxtostr for the GID conversion.
+	* m4/inttostr.m4 (gl_INTTOSTR): Add gl_PREREQ_GIDTOSTR and
+	gl_PREREQ_UIDTOSTR and define them.
+	* modules/inttostr: Add gidtostr.c and uidtostr.c to Files list.
+	(lib_SOURCES): Also add them here.
+	* tests/test-inttostr.c (main): Add a test for gidtostr/uidtostr.
+	* top/maint.mk (sc_prohibit_inttostr_without_use): Add gidtostr
+	and uidtostr to the pattern.
+
 2013-08-10  Paul Eggert  <egg...@cs.ucla.edu>
 
 	sys_time: port to OpenBSD
diff --git a/build-aux/prefix-gnulib-mk b/build-aux/prefix-gnulib-mk
index 4d0518f..8a3a0b3 100755
--- a/build-aux/prefix-gnulib-mk
+++ b/build-aux/prefix-gnulib-mk
@@ -158,12 +158,14 @@ sub prefix ($)
   # lib_libcoreutils_a_SOURCES += \
   #   imaxtostr.c \
   #   inttostr.c \
+  #   gidtostr.c \
   #   offtostr.c \
+  #   uidtostr.c \
   #   uinttostr.c \
   #   umaxtostr.c
   # The above are not handled since they're on continued lines, so
   # deal with them manually:
-  s{^(\s*)((?:[ui]max|u?int|off)tostr\.c(:? \\)?)$}{$1$prefix$2}gm;
+  s{^(\s*)((?:[ui]max|u?int|off|[gu]id)tostr\.c(:? \\)?)$}{$1$prefix$2}gm;
 
   # $(srcdir)/ is actually $(top_srcdir)/$prefix/.
   # The trailing slash is required to avoid matching this rule:
diff --git a/lib/gidtostr.c b/lib/gidtostr.c
new file mode 100644
index 0000000..3bf46ca
--- /dev/null
+++ b/lib/gidtostr.c
@@ -0,0 +1,3 @@
+#define anytostr gidtostr
+#define inttype gid_t
+#include "anytostr.c"
diff --git a/lib/inttostr.h b/lib/inttostr.h
index 4605145..d83e265 100644
--- a/lib/inttostr.h
+++ b/lib/inttostr.h
@@ -44,3 +44,5 @@ char *inttostr (int, char *) __attribute_warn_unused_result__;
 char *offtostr (off_t, char *) __attribute_warn_unused_result__;
 char *uinttostr (unsigned int, char *) __attribute_warn_unused_result__;
 char *umaxtostr (uintmax_t, char *) __attribute_warn_unused_result__;
+char *gidtostr (gid_t, char *) __attribute_warn_unused_result__;
+char *uidtostr (uid_t, char *) __attribute_warn_unused_result__;
diff --git a/lib/uidtostr.c b/lib/uidtostr.c
new file mode 100644
index 0000000..52cc143
--- /dev/null
+++ b/lib/uidtostr.c
@@ -0,0 +1,3 @@
+#define anytostr uidtostr
+#define inttype uid_t
+#include "anytostr.c"
diff --git a/lib/userspec.c b/lib/userspec.c
index d760996..04ac646 100644
--- a/lib/userspec.c
+++ b/lib/userspec.c
@@ -185,7 +185,7 @@ parse_with_separator (char const *spec, char const *separator,
               char buf[INT_BUFSIZE_BOUND (uintmax_t)];
               gnum = pwd->pw_gid;
               grp = getgrgid (gnum);
-              gname = xstrdup (grp ? grp->gr_name : umaxtostr (gnum, buf));
+              gname = xstrdup (grp ? grp->gr_name : gidtostr (gnum, buf));
               endgrent ();
             }
         }
diff --git a/m4/inttostr.m4 b/m4/inttostr.m4
index 1a0ce74..09de883 100644
--- a/m4/inttostr.m4
+++ b/m4/inttostr.m4
@@ -11,6 +11,8 @@ AC_DEFUN([gl_INTTOSTR],
   gl_PREREQ_OFFTOSTR
   gl_PREREQ_UMAXTOSTR
   gl_PREREQ_UINTTOSTR
+  gl_PREREQ_GIDTOSTR
+  gl_PREREQ_UIDTOSTR
 ])
 
 # Prerequisites of lib/inttostr.h.
@@ -30,3 +32,9 @@ AC_DEFUN([gl_PREREQ_UMAXTOSTR], [:])
 
 # Prerequisites of lib/uinttostr.c.
 AC_DEFUN([gl_PREREQ_UINTTOSTR], [:])
+
+# Prerequisites of lib/gidtostr.c.
+AC_DEFUN([gl_PREREQ_GIDTOSTR], [:])
+
+# Prerequisites of lib/uidtostr.c.
+AC_DEFUN([gl_PREREQ_UIDTOSTR], [:])
diff --git a/modules/inttostr b/modules/inttostr
index 9eecea8..e70d9f6 100644
--- a/modules/inttostr
+++ b/modules/inttostr
@@ -9,6 +9,8 @@ lib/inttostr.h
 lib/offtostr.c
 lib/umaxtostr.c
 lib/uinttostr.c
+lib/gidtostr.c
+lib/uidtostr.c
 m4/inttostr.m4
 
 Depends-on:
@@ -20,9 +22,11 @@ gl_INTTOSTR
 
 Makefile.am:
 lib_SOURCES += \
+  gidtostr.c \
   imaxtostr.c \
   inttostr.c \
   offtostr.c \
+  uidtostr.c \
   uinttostr.c \
   umaxtostr.c
 
diff --git a/tests/test-inttostr.c b/tests/test-inttostr.c
index 8f21a1c..05e691c 100644
--- a/tests/test-inttostr.c
+++ b/tests/test-inttostr.c
@@ -80,6 +80,8 @@ main (void)
       CK (off_t,        offtostr);
       CK (uintmax_t,    umaxtostr);
       CK (intmax_t,     imaxtostr);
+      CK (gid_t,        gidtostr);
+      CK (uid_t,        uidtostr);
       return 0;
     }
 
diff --git a/top/maint.mk b/top/maint.mk
index c1b786f..3166256 100644
--- a/top/maint.mk
+++ b/top/maint.mk
@@ -507,7 +507,7 @@ sc_prohibit_long_options_without_use:
 
 # Don't include this header unless you use one of its functions.
 sc_prohibit_inttostr_without_use:
-	@h='inttostr.h' re='\<(off|[iu]max|uint)tostr *\(' \
+	@h='inttostr.h' re='\<(off|[iu]max|uint|[gu]id)tostr *\(' \
 	  $(_sc_header_without_use)
 
 # Don't include this header unless you use one of its functions.
-- 
1.8.3.1

Reply via email to