diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/include/pg_config.h.in | 7 | ||||
-rw-r--r-- | src/include/pg_config.h.win32 | 7 | ||||
-rw-r--r-- | src/include/port.h | 4 | ||||
-rw-r--r-- | src/interfaces/libpq/.gitignore | 1 | ||||
-rw-r--r-- | src/interfaces/libpq/Makefile | 6 | ||||
-rw-r--r-- | src/port/strnlen.c | 33 |
6 files changed, 55 insertions, 3 deletions
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in index a27eb57048c..292d6924f8e 100644 --- a/src/include/pg_config.h.in +++ b/src/include/pg_config.h.in @@ -150,6 +150,10 @@ don't. */ #undef HAVE_DECL_STRLCPY +/* Define to 1 if you have the declaration of `strnlen', and to 0 if you + don't. */ +#undef HAVE_DECL_STRNLEN + /* Define to 1 if you have the declaration of `strtoll', and to 0 if you don't. */ #undef HAVE_DECL_STRTOLL @@ -504,6 +508,9 @@ /* Define to 1 if you have the `strlcpy' function. */ #undef HAVE_STRLCPY +/* Define to 1 if you have the `strnlen' function. */ +#undef HAVE_STRNLEN + /* Define to use have a strong random number source */ #undef HAVE_STRONG_RANDOM diff --git a/src/include/pg_config.h.win32 b/src/include/pg_config.h.win32 index 422ea6f703b..20aaa2d6a9a 100644 --- a/src/include/pg_config.h.win32 +++ b/src/include/pg_config.h.win32 @@ -102,6 +102,10 @@ don't. */ #define HAVE_DECL_SNPRINTF 1 +/* Define to 1 if you have the declaration of `strnlen', and to 0 if you + don't. */ +#define HAVE_DECL_STRNLEN 1 + /* Define to 1 if you have the declaration of `strtoll', and to 0 if you don't. */ #define HAVE_DECL_STRTOLL 1 @@ -271,6 +275,9 @@ /* Define to 1 if you have the <pam/pam_appl.h> header file. */ /* #undef HAVE_PAM_PAM_APPL_H */ +/* Define to 1 if you have the `strnlen' function. */ +#define HAVE_STRNLEN 1 + /* Define to 1 if you have the `poll' function. */ /* #undef HAVE_POLL */ diff --git a/src/include/port.h b/src/include/port.h index 52deede1939..74992715e4a 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -409,6 +409,10 @@ extern size_t strlcat(char *dst, const char *src, size_t siz); extern size_t strlcpy(char *dst, const char *src, size_t siz); #endif +#if !HAVE_DECL_STRNLEN +extern size_t strnlen(const char *str, size_t maxlen); +#endif + #if !defined(HAVE_RANDOM) extern long random(void); #endif diff --git a/src/interfaces/libpq/.gitignore b/src/interfaces/libpq/.gitignore index 6c02dc70551..5c232ae2d11 100644 --- a/src/interfaces/libpq/.gitignore +++ b/src/interfaces/libpq/.gitignore @@ -18,6 +18,7 @@ /snprintf.c /strerror.c /strlcpy.c +/strnlen.c /thread.c /win32error.c /win32setlocale.c diff --git a/src/interfaces/libpq/Makefile b/src/interfaces/libpq/Makefile index 87f22d242fb..94eb84be030 100644 --- a/src/interfaces/libpq/Makefile +++ b/src/interfaces/libpq/Makefile @@ -38,7 +38,7 @@ OBJS= fe-auth.o fe-auth-scram.o fe-connect.o fe-exec.o fe-misc.o fe-print.o fe-l OBJS += chklocale.o inet_net_ntop.o noblock.o pgstrcasecmp.o pqsignal.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 win32error.o win32setlocale.o, $(LIBOBJS)) +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)) ifeq ($(enable_strong_random), yes) OBJS += pg_strong_random.o @@ -103,7 +103,7 @@ backend_src = $(top_srcdir)/src/backend # the module is needed (see filter hack in OBJS, above). # When you add a file here, remember to add it in the "clean" target below. -chklocale.c crypt.c erand48.c getaddrinfo.c getpeereid.c inet_aton.c inet_net_ntop.c noblock.c open.c system.c pgsleep.c pg_strong_random.c pgstrcasecmp.c pqsignal.c snprintf.c strerror.c strlcpy.c thread.c win32error.c win32setlocale.c: % : $(top_srcdir)/src/port/% +chklocale.c crypt.c erand48.c getaddrinfo.c getpeereid.c inet_aton.c inet_net_ntop.c noblock.c open.c system.c pgsleep.c pg_strong_random.c pgstrcasecmp.c pqsignal.c snprintf.c strerror.c strlcpy.c strnlen.c thread.c win32error.c win32setlocale.c: % : $(top_srcdir)/src/port/% rm -f $@ && $(LN_S) $< . ip.c md5.c base64.c scram-common.c sha2.c sha2_openssl.c saslprep.c unicode_norm.c: % : $(top_srcdir)/src/common/% @@ -155,7 +155,7 @@ clean distclean: clean-lib # Might be left over from a Win32 client-only build rm -f pg_config_paths.h # Remove files we (may have) symlinked in from src/port and other places - rm -f chklocale.c crypt.c erand48.c getaddrinfo.c getpeereid.c inet_aton.c inet_net_ntop.c noblock.c open.c system.c pgsleep.c pg_strong_random.c pgstrcasecmp.c pqsignal.c snprintf.c strerror.c strlcpy.c thread.c win32error.c win32setlocale.c + rm -f chklocale.c crypt.c erand48.c getaddrinfo.c getpeereid.c inet_aton.c inet_net_ntop.c noblock.c open.c system.c pgsleep.c pg_strong_random.c pgstrcasecmp.c pqsignal.c snprintf.c strerror.c strlcpy.c strnlen.c thread.c win32error.c win32setlocale.c rm -f ip.c md5.c base64.c scram-common.c sha2.c sha2_openssl.c saslprep.c unicode_norm.c rm -f encnames.c wchar.c diff --git a/src/port/strnlen.c b/src/port/strnlen.c new file mode 100644 index 00000000000..260b883368b --- /dev/null +++ b/src/port/strnlen.c @@ -0,0 +1,33 @@ +/*------------------------------------------------------------------------- + * + * strnlen.c + * Fallback implementation of strnlen(). + * + * + * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/port/strnlen.c + * + *------------------------------------------------------------------------- + */ + +#include "c.h" + +/* + * Implementation of posix' strnlen for systems where it's not available. + * + * Returns the number of characters before a null-byte in the string pointed + * to by str, unless there's no null-byte before maxlen. In the latter case + * maxlen is returned. + */ +size_t +strnlen(const char *str, size_t maxlen) +{ + const char *p = str; + + while (maxlen-- > 0 && *p) + p++; + return p - str; +} |