aboutsummaryrefslogtreecommitdiff
path: root/src/include/common/string.h
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2017-10-09 15:20:42 -0700
committerAndres Freund <andres@anarazel.de>2017-10-09 15:20:42 -0700
commit8a241792f968ed5be6cf4d41e32c0d264f6c0c65 (patch)
tree80391a1d37c432548e50d07a58a484278c202f74 /src/include/common/string.h
parent71c75ddfbb277362bf62dc5b1645c3903e16bc34 (diff)
downloadpostgresql-8a241792f968ed5be6cf4d41e32c0d264f6c0c65.tar.gz
postgresql-8a241792f968ed5be6cf4d41e32c0d264f6c0c65.zip
Add pg_strnlen() a portable implementation of strlen.
As the OS version is likely going to be more optimized, fall back to it if available, as detected by configure.
Diffstat (limited to 'src/include/common/string.h')
-rw-r--r--src/include/common/string.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/include/common/string.h b/src/include/common/string.h
index 5f3ea71d613..3d46b80918c 100644
--- a/src/include/common/string.h
+++ b/src/include/common/string.h
@@ -12,4 +12,19 @@
extern bool pg_str_endswith(const char *str, const char *end);
+/*
+ * Portable version of posix' strnlen.
+ *
+ * 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.
+ *
+ * Use the system strnlen if provided, it's likely to be faster.
+ */
+#ifdef HAVE_STRNLEN
+#define pg_strnlen(str, maxlen) strnlen(str, maxlen)
+#else
+extern size_t pg_strnlen(const char *str, size_t maxlen);
+#endif
+
#endif /* COMMON_STRING_H */