1
0
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:
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

@@ -2,4 +2,5 @@
/blibecpg_compatdll.def
/exports.list
/snprintf.c
/strerror.c
/strnlen.c

View File

@@ -31,7 +31,7 @@ SHLIB_EXPORTS = exports.txt
# Need to recompile any libpgport object files
LIBS := $(filter-out -lpgport, $(LIBS))
OBJS= informix.o $(filter snprintf.o strnlen.o, $(LIBOBJS)) $(WIN32RES)
OBJS= informix.o strerror.o $(filter snprintf.o strnlen.o, $(LIBOBJS)) $(WIN32RES)
PKG_CONFIG_REQUIRES_PRIVATE = libecpg libpgtypes
@@ -48,7 +48,7 @@ submake-pgtypeslib:
# Shared library stuff
include $(top_srcdir)/src/Makefile.shlib
snprintf.c strnlen.c: % : $(top_srcdir)/src/port/%
snprintf.c strerror.c strnlen.c: % : $(top_srcdir)/src/port/%
rm -f $@ && $(LN_S) $< .
install: all installdirs install-lib
@@ -58,6 +58,6 @@ installdirs: installdirs-lib
uninstall: uninstall-lib
clean distclean: clean-lib
rm -f $(OBJS) snprintf.c strnlen.c
rm -f $(OBJS) snprintf.c strerror.c strnlen.c
maintainer-clean: distclean maintainer-clean-lib

View File

@@ -4,6 +4,7 @@
/path.c
/pgstrcasecmp.c
/snprintf.c
/strerror.c
/strlcpy.c
/strnlen.c
/thread.c

View File

@@ -26,7 +26,7 @@ override CFLAGS += $(PTHREAD_CFLAGS)
LIBS := $(filter-out -lpgport, $(LIBS))
OBJS= execute.o typename.o descriptor.o sqlda.o data.o error.o prepare.o memory.o \
connect.o misc.o path.o pgstrcasecmp.o \
connect.o misc.o path.o pgstrcasecmp.o strerror.o \
$(filter snprintf.o strlcpy.o strnlen.o win32setlocale.o isinf.o, $(LIBOBJS)) \
$(WIN32RES)
@@ -57,7 +57,7 @@ include $(top_srcdir)/src/Makefile.shlib
# necessarily use the same object files as the backend uses. Instead,
# symlink the source files in here and build our own object file.
path.c pgstrcasecmp.c snprintf.c strlcpy.c strnlen.c thread.c win32setlocale.c isinf.c: % : $(top_srcdir)/src/port/%
path.c pgstrcasecmp.c snprintf.c strerror.c strlcpy.c strnlen.c thread.c win32setlocale.c isinf.c: % : $(top_srcdir)/src/port/%
rm -f $@ && $(LN_S) $< .
misc.o: misc.c $(top_builddir)/src/port/pg_config_paths.h
@@ -74,6 +74,6 @@ uninstall: uninstall-lib
clean distclean: clean-lib
rm -f $(OBJS)
rm -f path.c pgstrcasecmp.c snprintf.c strlcpy.c strnlen.c thread.c win32setlocale.c isinf.c
rm -f path.c pgstrcasecmp.c snprintf.c strerror.c strlcpy.c strnlen.c thread.c win32setlocale.c isinf.c
maintainer-clean: distclean maintainer-clean-lib

View File

@@ -4,5 +4,6 @@
/pgstrcasecmp.c
/rint.c
/snprintf.c
/strerror.c
/string.c
/strnlen.c

View File

@@ -30,7 +30,7 @@ SHLIB_LINK += $(filter -lm, $(LIBS))
SHLIB_EXPORTS = exports.txt
OBJS= numeric.o datetime.o common.o dt_common.o timestamp.o interval.o \
pgstrcasecmp.o \
pgstrcasecmp.o strerror.o \
$(filter rint.o snprintf.o strnlen.o, $(LIBOBJS)) \
string.o \
$(WIN32RES)
@@ -45,7 +45,7 @@ include $(top_srcdir)/src/Makefile.shlib
# necessarily use the same object files as the backend uses. Instead,
# symlink the source files in here and build our own object file.
pgstrcasecmp.c rint.c snprintf.c strnlen.c: % : $(top_srcdir)/src/port/%
pgstrcasecmp.c rint.c snprintf.c strerror.c strnlen.c: % : $(top_srcdir)/src/port/%
rm -f $@ && $(LN_S) $< .
string.c: % : $(top_srcdir)/src/common/%
@@ -58,6 +58,6 @@ installdirs: installdirs-lib
uninstall: uninstall-lib
clean distclean: clean-lib
rm -f $(OBJS) pgstrcasecmp.c rint.c snprintf.c strnlen.c string.c
rm -f $(OBJS) pgstrcasecmp.c rint.c snprintf.c strerror.c strnlen.c string.c
maintainer-clean: distclean maintainer-clean-lib

View File

@@ -36,9 +36,9 @@ OBJS= fe-auth.o fe-auth-scram.o fe-connect.o fe-exec.o fe-misc.o fe-print.o fe-l
libpq-events.o
# libpgport C files we always use
OBJS += chklocale.o inet_net_ntop.o noblock.o pgstrcasecmp.o pqsignal.o \
thread.o
strerror.o thread.o
# libpgport C files that are needed if identified by configure
OBJS += $(filter crypt.o getaddrinfo.o getpeereid.o inet_aton.o open.o system.o snprintf.o strerror.o strlcpy.o strnlen.o win32error.o win32setlocale.o, $(LIBOBJS))
OBJS += $(filter crypt.o getaddrinfo.o getpeereid.o inet_aton.o open.o system.o snprintf.o strlcpy.o strnlen.o win32error.o win32setlocale.o, $(LIBOBJS))
ifeq ($(enable_strong_random), yes)
OBJS += pg_strong_random.o