From 6cbc4ec426b00a8b920c758f408530e1a63fdf37 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 15 Jul 2015 10:43:56 -0700 Subject: [PATCH] lib: replace: Add strsep function (missing on Solaris). BUG: https://bugzilla.samba.org/show_bug.cgi?id=11359 Signed-off-by: Jeremy Allison --- lib/replace/replace.c | 20 ++++++++++++++++++++ lib/replace/replace.h | 5 +++++ lib/replace/wscript | 4 ++-- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/replace/replace.c b/lib/replace/replace.c index dccf514..0806ce3 100644 --- a/lib/replace/replace.c +++ b/lib/replace/replace.c @@ -475,6 +475,26 @@ char *rep_strcasestr(const char *haystack, const char *needle) } #endif +#ifndef HAVE_STRSEP +char *rep_strsep(char **pps, const char *delim) +{ + char *ret = *pps; + char *p = *pps; + + if (p == NULL) { + return NULL; + } + p += strcspn(p, delim); + if (*p == '\0') { + *pps = NULL; + } else { + *p = '\0'; + *pps = p + 1; + } + return ret; +} +#endif + #ifndef HAVE_STRTOK_R /* based on GLIBC version, copyright Free Software Foundation */ char *rep_strtok_r(char *s, const char *delim, char **save_ptr) diff --git a/lib/replace/replace.h b/lib/replace/replace.h index 3ff4e36..c764d06 100644 --- a/lib/replace/replace.h +++ b/lib/replace/replace.h @@ -349,6 +349,11 @@ void rep_setlinebuf(FILE *); char *rep_strcasestr(const char *haystack, const char *needle); #endif +#ifndef HAVE_STRSEP +#define strsep rep_strsep +char *rep_strsep(char **pps, const char *delim); +#endif + #ifndef HAVE_STRTOK_R #define strtok_r rep_strtok_r char *rep_strtok_r(char *s, const char *delim, char **save_ptr); diff --git a/lib/replace/wscript b/lib/replace/wscript index 516db2f..30eede2 100644 --- a/lib/replace/wscript +++ b/lib/replace/wscript @@ -240,7 +240,7 @@ def configure(conf): conf.CHECK_FUNCS('lstat getpgrp utime utimes setuid seteuid setreuid setresuid setgid setegid') conf.CHECK_FUNCS('setregid setresgid chroot strerror vsyslog setlinebuf mktime') conf.CHECK_FUNCS('ftruncate chsize rename waitpid wait4') - conf.CHECK_FUNCS('initgroups pread pwrite strndup strcasestr') + conf.CHECK_FUNCS('initgroups pread pwrite strndup strcasestr strsep') conf.CHECK_FUNCS('strtok_r mkdtemp dup2 dprintf vdprintf isatty chown lchown') conf.CHECK_FUNCS('link readlink symlink realpath snprintf vsnprintf') conf.CHECK_FUNCS('asprintf vasprintf setenv unsetenv strnlen strtoull __strtoull') @@ -630,7 +630,7 @@ REPLACEMENT_FUNCTIONS = { 'memmove', 'strdup', 'setlinebuf', 'vsyslog', 'strnlen', 'strndup', 'waitpid', 'seteuid', 'setegid', 'chroot', 'mkstemp', 'mkdtemp', 'pread', 'pwrite', 'strcasestr', - 'strtok_r', 'strtoll', 'strtoull', 'setenv', 'unsetenv', + 'strsep', 'strtok_r', 'strtoll', 'strtoull', 'setenv', 'unsetenv', 'utime', 'utimes', 'dup2', 'chown', 'link', 'readlink', 'symlink', 'lchown', 'realpath', 'memmem', 'vdprintf', 'dprintf', 'get_current_dir_name', -- 2.4.3.573.g4eafbef