summaryrefslogtreecommitdiff
path: root/src/backend/port
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2018-09-26 11:06:42 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2018-09-26 11:06:42 -0400
commit26e9d4d4ef16b5e2be96319f89ea6ba7f63a4d73 (patch)
tree99ad7fa2f1784ce775cbf6ed50026367d6990da4 /src/backend/port
parenta49ceda6a044c2fc104b3d1397fe0bef8679d1aa (diff)
downloadpostgresql-26e9d4d4ef16b5e2be96319f89ea6ba7f63a4d73.tar.gz
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
Diffstat (limited to 'src/backend/port')
-rw-r--r--src/backend/port/win32/socket.c36
1 files changed, 0 insertions, 36 deletions
diff --git a/src/backend/port/win32/socket.c b/src/backend/port/win32/socket.c
index f4356fe1f3..af35cfbbb3 100644
--- a/src/backend/port/win32/socket.c
+++ b/src/backend/port/win32/socket.c
@@ -690,39 +690,3 @@ pgwin32_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, c
memcpy(writefds, &outwritefds, sizeof(fd_set));
return nummatches;
}
-
-
-/*
- * Return win32 error string, since strerror can't
- * handle winsock codes
- */
-static char wserrbuf[256];
-const char *
-pgwin32_socket_strerror(int err)
-{
- static HANDLE handleDLL = INVALID_HANDLE_VALUE;
-
- if (handleDLL == INVALID_HANDLE_VALUE)
- {
- handleDLL = LoadLibraryEx("netmsg.dll", NULL, DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE);
- if (handleDLL == NULL)
- ereport(FATAL,
- (errmsg_internal("could not load netmsg.dll: error code %lu", GetLastError())));
- }
-
- ZeroMemory(&wserrbuf, sizeof(wserrbuf));
- if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_FROM_HMODULE,
- handleDLL,
- err,
- MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT),
- wserrbuf,
- sizeof(wserrbuf) - 1,
- NULL) == 0)
- {
- /* Failed to get id */
- sprintf(wserrbuf, "unrecognized winsock error %d", err);
- }
- return wserrbuf;
-}