summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndres Freund2015-01-03 19:51:52 +0000
committerAndres Freund2015-01-03 19:54:13 +0000
commitbb2e2ce6e2ea4835ed99593508d0909af0e402d6 (patch)
treea6e9cda6618e7b7e5e20cac7ddbb258ab31204d5 /src
parent15331540cde241e63a8d29a6a594d2b637d9102c (diff)
Add pg_string_endswith as the start of a string helper library in src/common.
Backpatch to 9.3 where src/common was introduce, because a bugfix that needs to be backpatched, requires the function. Earlier branches will have to duplicate the code.
Diffstat (limited to 'src')
-rw-r--r--src/common/Makefile2
-rw-r--r--src/common/string.c43
-rw-r--r--src/include/common/string.h15
-rw-r--r--src/tools/msvc/Mkvcbuild.pm2
4 files changed, 60 insertions, 2 deletions
diff --git a/src/common/Makefile b/src/common/Makefile
index cd97980ce66..b5889f7380f 100644
--- a/src/common/Makefile
+++ b/src/common/Makefile
@@ -23,7 +23,7 @@ include $(top_builddir)/src/Makefile.global
override CPPFLAGS := -DFRONTEND $(CPPFLAGS)
LIBS += $(PTHREAD_LIBS)
-OBJS_COMMON = relpath.o
+OBJS_COMMON = relpath.o string.o
OBJS_FRONTEND = $(OBJS_COMMON) fe_memutils.o
diff --git a/src/common/string.c b/src/common/string.c
new file mode 100644
index 00000000000..27e074313d6
--- /dev/null
+++ b/src/common/string.c
@@ -0,0 +1,43 @@
+/*-------------------------------------------------------------------------
+ *
+ * string.c
+ * string handling helpers
+ *
+ *
+ * Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ *
+ * IDENTIFICATION
+ * src/common/string.c
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+#ifndef FRONTEND
+#include "postgres.h"
+#else
+#include "postgres_fe.h"
+#endif
+
+#include "common/string.h"
+
+
+/*
+ * Returns whether the string `str' has the postfix `end'.
+ */
+bool
+pg_str_endswith(const char *str, const char *end)
+{
+ size_t slen = strlen(str);
+ size_t elen = strlen(end);
+
+ /* can't be a postfix if longer */
+ if (elen > slen)
+ return false;
+
+ /* compare the end of the strings */
+ str += slen - elen;
+ return strcmp(str, end) == 0;
+}
diff --git a/src/include/common/string.h b/src/include/common/string.h
new file mode 100644
index 00000000000..023385856fa
--- /dev/null
+++ b/src/include/common/string.h
@@ -0,0 +1,15 @@
+/*
+ * string.h
+ * string handling helpers
+ *
+ * Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * src/include/common/string.h
+ */
+#ifndef COMMON_STRING_H
+#define COMMON_STRING_H
+
+extern bool pg_str_endswith(const char *str, const char *end);
+
+#endif /* COMMON_STRING_H */
diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm
index 00a25b9f87e..94c7fee8556 100644
--- a/src/tools/msvc/Mkvcbuild.pm
+++ b/src/tools/msvc/Mkvcbuild.pm
@@ -76,7 +76,7 @@ sub mkvcbuild
push(@pgportfiles, 'rint.c') if ($vsVersion < '12.00');
our @pgcommonallfiles = qw(
- relpath.c);
+ relpath.c string.c);
our @pgcommonfrontendfiles = (@pgcommonallfiles, qw(fe_memutils.c));