aboutsummaryrefslogtreecommitdiff
path: root/src/port/thread.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/port/thread.c')
-rw-r--r--src/port/thread.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/port/thread.c b/src/port/thread.c
index 1568803d626..aab74516ac9 100644
--- a/src/port/thread.c
+++ b/src/port/thread.c
@@ -83,6 +83,12 @@ pqStrerror(int errnum, char *strerrbuf, size_t buflen)
/*
* Wrapper around getpwuid() or getpwuid_r() to mimic POSIX getpwuid_r()
* behaviour, if it is not available or required.
+ *
+ * Per POSIX, the possible cases are:
+ * success: returns zero, *result is non-NULL
+ * uid not found: returns zero, *result is NULL
+ * error during lookup: returns an errno code, *result is NULL
+ * (caller should *not* assume that the errno variable is set)
*/
#ifndef WIN32
int
@@ -93,22 +99,25 @@ pqGetpwuid(uid_t uid, struct passwd * resultbuf, char *buffer,
#ifdef GETPWUID_R_5ARG
/* POSIX version */
- getpwuid_r(uid, resultbuf, buffer, buflen, result);
+ return getpwuid_r(uid, resultbuf, buffer, buflen, result);
#else
/*
* Early POSIX draft of getpwuid_r() returns 'struct passwd *'.
* getpwuid_r(uid, resultbuf, buffer, buflen)
*/
+ errno = 0;
*result = getpwuid_r(uid, resultbuf, buffer, buflen);
+ /* paranoia: ensure we return zero on success */
+ return (*result == NULL) ? errno : 0;
#endif
#else
-
/* no getpwuid_r() available, just use getpwuid() */
+ errno = 0;
*result = getpwuid(uid);
+ /* paranoia: ensure we return zero on success */
+ return (*result == NULL) ? errno : 0;
#endif
-
- return (*result == NULL) ? -1 : 0;
}
#endif