mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +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:
@@ -189,6 +189,10 @@ extern int pg_printf(const char *fmt,...) pg_attribute_printf(1, 2);
|
||||
#endif
|
||||
#endif /* USE_REPL_SNPRINTF */
|
||||
|
||||
/* Replace strerror() with our own, somewhat more robust wrapper */
|
||||
extern char *pg_strerror(int errnum);
|
||||
#define strerror pg_strerror
|
||||
|
||||
/* Portable prompt handling */
|
||||
extern void simple_prompt(const char *prompt, char *destination, size_t destlen,
|
||||
bool echo);
|
||||
@@ -355,7 +359,7 @@ extern int isinf(double x);
|
||||
#undef isinf
|
||||
#define isinf __builtin_isinf
|
||||
#endif /* __has_builtin(isinf) */
|
||||
#endif /* __clang__ && !__cplusplus*/
|
||||
#endif /* __clang__ && !__cplusplus */
|
||||
#endif /* !HAVE_ISINF */
|
||||
|
||||
#ifndef HAVE_MKDTEMP
|
||||
@@ -403,7 +407,7 @@ extern void srandom(unsigned int seed);
|
||||
#ifndef HAVE_DLOPEN
|
||||
extern void *dlopen(const char *file, int mode);
|
||||
extern void *dlsym(void *handle, const char *symbol);
|
||||
extern int dlclose(void *handle);
|
||||
extern int dlclose(void *handle);
|
||||
extern char *dlerror(void);
|
||||
#endif
|
||||
|
||||
|
Reference in New Issue
Block a user