1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-25 13:17:41 +03:00

Convert elog.c's useful_strerror() into a globally-used strerror wrapper.

elog.c has long had a private strerror wrapper that handles assorted
possible failures or deficiencies of the platform's strerror.  On Windows,
it also knows how to translate Winsock error codes, which the native
strerror does not.  Move all this code into src/port/strerror.c and
define strerror() as a macro that invokes it, so that both our frontend
and backend code will have all of this behavior.

I believe this constitutes an actual bug fix on Windows, since AFAICS
our frontend code did not report Winsock error codes properly before this.
However, the main point is to lay the groundwork for implementing %m
in src/port/snprintf.c: the behavior we want %m to have is this one,
not the native strerror's.

Note that this throws away the prior use of src/port/strerror.c,
which was to implement strerror() on platforms lacking it.  That's
been dead code for nigh twenty years now, since strerror() was
already required by C89.

We should likewise cause strerror_r to use this behavior, but
I'll tackle that separately.

Patch by me, reviewed by Michael Paquier

Discussion: https://postgr.es/m/2975.1526862605@sss.pgh.pa.us
This commit is contained in:
Tom Lane
2018-09-26 11:06:42 -04:00
parent a49ceda6a0
commit 26e9d4d4ef
19 changed files with 299 additions and 311 deletions

View File

@@ -322,8 +322,8 @@ extern int pgwin32_safestat(const char *path, struct stat *buf);
* Supplement to <errno.h>.
*
* We redefine network-related Berkeley error symbols as the corresponding WSA
* constants. This allows elog.c to recognize them as being in the Winsock
* error code range and pass them off to pgwin32_socket_strerror(), since
* constants. This allows strerror.c to recognize them as being in the Winsock
* error code range and pass them off to win32_socket_strerror(), since
* Windows' version of plain strerror() won't cope. Note that this will break
* if these names are used for anything else besides Windows Sockets errors.
* See TranslateSocketError() when changing this list.
@@ -456,8 +456,6 @@ int pgwin32_connect(SOCKET s, const struct sockaddr *name, int namelen);
int pgwin32_select(int nfds, fd_set *readfs, fd_set *writefds, fd_set *exceptfds, const struct timeval *timeout);
int pgwin32_recv(SOCKET s, char *buf, int len, int flags);
int pgwin32_send(SOCKET s, const void *buf, int len, int flags);
const char *pgwin32_socket_strerror(int err);
int pgwin32_waitforsinglesocket(SOCKET s, int what, int timeout);
extern int pgwin32_noblock;