1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-28 18:48:04 +03:00

Incorporate strerror_r() into src/port/snprintf.c, too.

This provides the features that used to exist in useful_strerror()
for users of strerror_r(), too.  Also, standardize on the GNU convention
that strerror_r returns a char pointer that may not be NULL.

I notice that libpq's win32.c contains a variant version of strerror_r
that probably ought to be folded into strerror.c.  But lacking a
Windows environment, I should leave that to somebody else.

Discussion: https://postgr.es/m/2975.1526862605@sss.pgh.pa.us
This commit is contained in:
Tom Lane
2018-09-26 12:35:57 -04:00
parent 26e9d4d4ef
commit 758ce9b779
11 changed files with 99 additions and 83 deletions

View File

@@ -53,33 +53,6 @@
*/
/*
* Wrapper around strerror and strerror_r to use the former if it is
* available and also return a more useful value (the error string).
*/
char *
pqStrerror(int errnum, char *strerrbuf, size_t buflen)
{
#if defined(FRONTEND) && defined(ENABLE_THREAD_SAFETY) && defined(HAVE_STRERROR_R)
/* reentrant strerror_r is available */
#ifdef STRERROR_R_INT
/* SUSv3 version */
if (strerror_r(errnum, strerrbuf, buflen) == 0)
return strerrbuf;
else
return "Unknown error";
#else
/* GNU libc */
return strerror_r(errnum, strerrbuf, buflen);
#endif
#else
/* no strerror_r() available, just use strerror */
strlcpy(strerrbuf, strerror(errnum), buflen);
return strerrbuf;
#endif
}
/*
* Wrapper around getpwuid() or getpwuid_r() to mimic POSIX getpwuid_r()
* behaviour, if that function is not available or required.