aboutsummaryrefslogtreecommitdiff
path: root/libbb/my_getgrgid.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/my_getgrgid.c')
-rw-r--r--libbb/my_getgrgid.c46
1 files changed, 13 insertions, 33 deletions
diff --git a/libbb/my_getgrgid.c b/libbb/my_getgrgid.c
index 8c530964c..9ac14a34e 100644
--- a/libbb/my_getgrgid.c
+++ b/libbb/my_getgrgid.c
@@ -22,48 +22,28 @@
22 /* Hacked by Tito Ragusa (c) 2004 <farmatito@tiscali.it> to make it more 22 /* Hacked by Tito Ragusa (c) 2004 <farmatito@tiscali.it> to make it more
23 * flexible : 23 * flexible :
24 * 24 *
25 * if bufsize is > 0 char *group cannot be set to NULL 25 * if bufsize is > 0 char *group cannot be set to NULL.
26 * on success groupname is written on static allocated buffer 26 * On success groupname is written on static allocated buffer group
27 * on failure gid as string is written to buffer and NULL is returned 27 * (and a pointer to it is returned).
28 * if bufsize is = 0 char *group can be set to NULL 28 * On failure gid as string is written to static allocated buffer
29 * on success groupname is returned 29 * group and NULL is returned.
30 * on failure NULL is returned 30 * if bufsize is = 0 char *group can be set to NULL.
31 * if bufsize is < 0 char *group can be set to NULL 31 * On success groupname is returned.
32 * on success groupname is returned 32 * On failure NULL is returned.
33 * on failure an error message is printed and the program exits 33 * if bufsize is < 0 char *group can be set to NULL.
34 * On success groupname is returned.
35 * On failure an error message is printed and the program exits.
34 */ 36 */
35 37
36#include <stdio.h>
37#include <string.h>
38#include <assert.h>
39#include "libbb.h" 38#include "libbb.h"
40#include "pwd_.h"
41#include "grp_.h" 39#include "grp_.h"
42 40
43
44/* gets a groupname given a gid */ 41/* gets a groupname given a gid */
45char * my_getgrgid(char *group, long gid, int bufsize) 42char * my_getgrgid(char *group, long gid, int bufsize)
46{ 43{
47 struct group *mygroup; 44 struct group *mygroup = getgrgid(gid);
48 45
49 mygroup = getgrgid(gid); 46 return my_getug(group, (mygroup) ? mygroup->gr_name : (char *)mygroup, gid, bufsize, 'g');
50 if (mygroup==NULL) {
51 if(bufsize > 0) {
52 assert(group != NULL);
53 snprintf(group, bufsize, "%ld", (long)gid);
54 }
55 if( bufsize < 0 ) {
56 bb_error_msg_and_die("unknown gid %ld", (long)gid);
57 }
58 return NULL;
59 } else {
60 if(bufsize > 0)
61 {
62 assert(group != NULL);
63 return safe_strncpy(group, mygroup->gr_name, bufsize);
64 }
65 return mygroup->gr_name;
66 }
67} 47}
68 48
69 49