update changelog
[platform/upstream/acl.git] / getfacl / user_group.c
1 /*
2   File: user_group.c
3   (Linux Access Control List Management)
4
5   Copyright (C) 1999, 2000
6   Andreas Gruenbacher, <a.gruenbacher@bestbits.at>
7         
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2 of the License, or (at
11   your option) any later version.
12
13   This program is distributed in the hope that it will be useful, but
14   WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16   General Public License for more details.
17
18   You should have received a copy of the GNU General Public License
19   along with this library; if not, write to the Free Software
20   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21   USA.
22 */
23
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include "user_group.h"
27
28
29 const char *
30 user_name(uid_t uid, int numeric)
31 {
32         struct passwd *passwd = numeric ? NULL : getpwuid(uid);
33         static char uid_str[22];
34         int ret;
35
36         if (passwd != NULL)
37                 return passwd->pw_name;
38         ret = snprintf(uid_str, sizeof(uid_str), "%ld", (long)uid);
39         if (ret < 1 || (size_t)ret >= sizeof(uid_str))
40                 return "?";
41         return uid_str;
42 }
43
44
45 const char *
46 group_name(gid_t gid, int numeric)
47 {
48         struct group *group = numeric ? NULL : getgrgid(gid);
49         static char gid_str[22];
50         int ret;
51
52         if (group != NULL)
53                 return group->gr_name;
54         ret = snprintf(gid_str, sizeof(gid_str), "%ld", (long)gid);
55         if (ret < 1 || (size_t)ret >= sizeof(gid_str))
56                 return "?";
57         return gid_str;
58 }
59