#include "postgres.h"
#include <pwd.h>
#include <unistd.h>
#include "common/username.h"
Go to the source code of this file.
◆ 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;
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
52
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 | ) |
|
Definition at line 74 of file username.c.
75{
76 const char *user_name;
77 char *errstr;
78
80
81 if (!user_name)
82 {
85 }
86 return user_name;
87}
#define fprintf(file, fmt, msg)
const char * get_user_name(char **errstr)
References exit(), fprintf, get_user_name(), and progname.
Referenced by get_id(), and main().