summaryrefslogtreecommitdiff
path: root/src/group-list.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/group-list.c')
-rw-r--r--src/group-list.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/group-list.c b/src/group-list.c
index edbb3421..7d4995b5 100644
--- a/src/group-list.c
+++ b/src/group-list.c
@@ -1,5 +1,5 @@
/* group-list.c --Print a list of group IDs or names.
- Copyright (C) 1989-2012 Free Software Foundation, Inc.
+ Copyright (C) 1989-2013 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
@@ -88,6 +88,16 @@ print_group_list (const char *username,
return ok;
}
+/* Convert a gid_t to string. Do not use this function directly.
+ Instead, use it via the gidtostr macro.
+ Beware that it returns a pointer to static storage. */
+static char *
+gidtostr_ptr (gid_t const *gid)
+{
+ static char buf[INT_BUFSIZE_BOUND (uintmax_t)];
+ return umaxtostr (*gid, buf);
+}
+#define gidtostr(g) gidtostr_ptr (&(g))
/* Print the name or value of group ID GID. */
extern bool
@@ -107,9 +117,7 @@ print_group (gid_t gid, bool use_name)
}
}
- if (grp == NULL)
- printf ("%lu", (unsigned long int) gid);
- else
- printf ("%s", grp->gr_name);
+ char *s = grp ? grp->gr_name : gidtostr (gid);
+ fputs (s, stdout);
return ok;
}