1user_from_uid(3) BSD Library Functions Manual user_from_uid(3)
2
4 user_from_uid, uid_from_user, group_from_gid, gid_from_group — cache
5 password and group entries
6
8 Utility functions from BSD systems (libbsd, -lbsd)
9
11 #include <pwd.h>
12 (See libbsd(7) for include usage.)
13
14 int
15 uid_from_user(const char *name, uid_t *uid);
16
17 const char *
18 user_from_uid(uid_t uid, int nouser);
19
20 #include <grp.h>
21
22 int
23 gid_from_group(const char *name, gid_t *gid);
24
25 const char *
26 group_from_gid(gid_t gid, int nogroup);
27
29 The user_from_uid() function returns the user name associated with the
30 argument uid. The user name is cached so that multiple calls with the
31 same uid do not require additional calls to getpwuid(3). If there is no
32 user associated with the uid, a pointer is returned to a string represen‐
33 tation of the uid, unless the argument nouser is non-zero, in which case
34 a null pointer is returned.
35
36 The uid_from_user() function returns the user ID associated with the ar‐
37 gument name. The user ID is cached so that multiple calls with the same
38 name do not require additional calls to getpwnam(3). If there is no user
39 ID associated with the name, the uid_from_user() function returns -1;
40 otherwise it stores the user ID at the location pointed to by uid and re‐
41 turns 0.
42
43 The group_from_gid() function returns the group name associated with the
44 argument gid. The group name is cached so that multiple calls with the
45 same gid do not require additional calls to getgrgid(3). If there is no
46 group associated with the gid, a pointer is returned to a string repre‐
47 sentation of the gid, unless the argument nogroup is non-zero, in which
48 case a null pointer is returned.
49
50 The gid_from_group() function returns the group ID associated with the
51 argument name. The group ID is cached so that multiple calls with the
52 same name do not require additional calls to getgrnam(3). If there is no
53 group ID associated with the name, the gid_from_group() function returns
54 -1; otherwise it stores the group ID at the location pointed to by gid
55 and returns 0.
56
58 getgrgid(3), getpwuid(3)
59
61 The user_from_uid() and group_from_gid() functions first appeared in
62 4.4BSD.
63
64 The uid_from_user() and gid_from_group() functions were ported from
65 NetBSD and first appeared in OpenBSD 6.4.
66
67BSD September 13, 2018 BSD