Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Build strsep for platforms who don't have one

Change-Id: I5526e52d1ad0f183c65394447fe3e6881a2ff03d
Reviewed-on: http://review.couchbase.org/8906
Reviewed-by: Srinivas Vadlamani <srinivas@couchbase.com>
Tested-by: Srinivas Vadlamani <srinivas@couchbase.com>
  • Loading branch information...
commit 5ee60122086955fbe7be4c1456b261ec9772ae41 1 parent 6a26e91
@trondn trondn authored Srinivas Vadlamani committed
Showing with 31 additions and 0 deletions.
  1. +4 −0 Makefile.am
  2. +3 −0  configure.ac
  3. +24 −0 strsep.c
View
4 Makefile.am
@@ -47,6 +47,10 @@ if BUILD_DAEMON
moxi_SOURCES += daemon.c
endif
+if BUILD_STRSEP
+moxi_SOURCES += strsep.c
+endif
+
timedrun_SOURCES = timedrun.c
htgram_test_SOURCES = htgram_test.c htgram.c htgram.h
View
3  configure.ac
@@ -151,6 +151,9 @@ AC_CHECK_FUNCS(mlockall)
AC_CHECK_FUNCS(getpagesizes)
AC_CHECK_FUNCS(memcntl)
AC_CHECK_FUNCS(sigignore)
+AC_CHECK_FUNCS(strsep)
+
+AM_CONDITIONAL(BUILD_STRSEP, test "x$ac_cv_func_strsep" != "xyes")
AC_DEFUN([AC_C_ALIGNMENT],
[AC_CACHE_CHECK(for alignment, ac_cv_c_alignment,
View
24 strsep.c
@@ -0,0 +1,24 @@
+#include <string.h>
+
+char *strsep(char **stringp, const char *pattern) {
+ char *ptr = *stringp;
+
+ char *first = NULL;
+ int len = strlen(pattern);
+
+ for (int i = 0; i < len; ++i) {
+ char *n = strchr(*stringp, pattern[i]);
+ if (n != NULL && (first == NULL || n < first)) {
+ first = n;
+ }
+ }
+
+ if (first != NULL) {
+ *first = '\0';
+ *stringp = first + 1;
+ } else {
+ *stringp = NULL;
+ }
+
+ return ptr;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.