username.c File Reference
Include dependency graph for username.c:
Go to the source code of this file.
Function Documentation
◆ get_user_name()
const char * get_user_name
(
char **
errstr )
Definition at line 31 of file username.c.
32{
33#ifndef WIN32
34 struct passwd *pw;
35 uid_t user_id = geteuid();
36
37 *errstr = NULL;
38
39 errno = 0; /* clear errno before call */
40 pw = getpwuid(user_id);
41 if (!pw)
42 {
43 *errstr =
psprintf(
_(
"could not look up effective user ID %ld: %s"),
44 (long) user_id,
45 errno ?
strerror(errno) :
_(
"user does not exist"));
46 return NULL;
47 }
48
49 return pw->pw_name;
50#else
51 /* Microsoft recommends buffer size of UNLEN+1, where UNLEN = 256 */
52 /* "static" variable remains after function exit */
55
56 *errstr = NULL;
57
59 {
60 *errstr =
psprintf(
_(
"user name lookup failure: error code %lu"),
61 GetLastError());
62 return NULL;
63 }
64
66#endif
67}
char * psprintf(const char *fmt,...)
References _, len, psprintf(), strerror, and username.
Referenced by get_user_info(), and get_user_name_or_exit().
◆ get_user_name_or_exit()
const char * get_user_name_or_exit
(
const char *
progname )