diff options
| author | Andres Freund <andres@anarazel.de> | 2015-01-03 20:51:52 +0100 |
|---|---|---|
| committer | Andres Freund <andres@anarazel.de> | 2015-01-03 20:54:12 +0100 |
| commit | ccb161b66addc9d0ede31359c05f7e9df61ab8d4 (patch) | |
| tree | 71a9798e0fd2ad3117d972167fde404379f0f48b /src/common | |
| parent | d6657d2a107bee20d63ec2f776d873242f9355e9 (diff) | |
| download | postgresql-ccb161b66addc9d0ede31359c05f7e9df61ab8d4.tar.gz | |
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/common')
| -rw-r--r-- | src/common/Makefile | 2 | ||||
| -rw-r--r-- | src/common/string.c | 43 |
2 files changed, 44 insertions, 1 deletions
diff --git a/src/common/Makefile b/src/common/Makefile index 7edbaaa2c1..e5c345d7de 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 = exec.o pgfnames.o psprintf.o relpath.o rmtree.o username.o wait_error.o +OBJS_COMMON = exec.o pgfnames.o psprintf.o relpath.o rmtree.o string.o username.o wait_error.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 0000000000..27e074313d --- /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; +} |
