1/*-------------------------------------------------------------------------
6 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/common/username.c
12 *-------------------------------------------------------------------------
27 * Returns the current user name in a static buffer
28 * On error, returns NULL and sets *errstr to point to a palloc'd message
35 uid_t user_id = geteuid();
39 errno = 0;
/* clear errno before call */
40 pw = getpwuid(user_id);
43 *errstr =
psprintf(
_(
"could not look up effective user ID %ld: %s"),
45 errno ?
strerror(errno) :
_(
"user does not exist"));
51 /* Microsoft recommends buffer size of UNLEN+1, where UNLEN = 256 */
52 /* "static" variable remains after function exit */
60 *errstr =
psprintf(
_(
"user name lookup failure: error code %lu"),
71 * Returns the current user name in a static buffer or exits
76 const char *user_name;
#define fprintf(file, fmt, msg)
char * psprintf(const char *fmt,...)
const char * get_user_name(char **errstr)
const char * get_user_name_or_exit(const char *progname)