diff options
Diffstat (limited to 'src/common/username.c')
-rw-r--r-- | src/common/username.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/common/username.c b/src/common/username.c index 24c5b47627..686a6a43c5 100644 --- a/src/common/username.c +++ b/src/common/username.c @@ -3,7 +3,7 @@ * username.c * get user name * - * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION @@ -26,8 +26,8 @@ #include "common/username.h" /* - * Returns the current user name in a static buffer, or NULL on error and - * sets errstr + * Returns the current user name in a static buffer + * On error, returns NULL and sets *errstr to point to a palloc'd message */ const char * get_user_name(char **errstr) @@ -42,7 +42,7 @@ get_user_name(char **errstr) pw = getpwuid(user_id); if (!pw) { - *errstr = psprintf(_("failed to look up effective user id %ld: %s"), + *errstr = psprintf(_("could not look up effective user ID %ld: %s"), (long) user_id, errno ? strerror(errno) : _("user does not exist")); return NULL; @@ -50,15 +50,17 @@ get_user_name(char **errstr) return pw->pw_name; #else - /* UNLEN = 256, 'static' variable remains after function exit */ + /* Microsoft recommends buffer size of UNLEN+1, where UNLEN = 256 */ + /* "static" variable remains after function exit */ static char username[256 + 1]; - DWORD len = sizeof(username) - 1; + DWORD len = sizeof(username); *errstr = NULL; if (!GetUserName(username, &len)) { - *errstr = psprintf(_("user name lookup failure: %s"), strerror(errno)); + *errstr = psprintf(_("user name lookup failure: error code %lu"), + GetLastError()); return NULL; } |