From 19651317844d7f7760b70bd0224c256709a9a1f1 Mon Sep 17 00:00:00 2001 From: troky Date: Sat, 21 Jun 2014 10:33:06 +0200 Subject: [PATCH] Moved strsep() implementation from winbuild.h to compat.h --- compat.h | 29 +++++++++++++++++------------ winbuild/dist/include/winbuild.h | 32 ++++---------------------------- 2 files changed, 21 insertions(+), 40 deletions(-) diff --git a/compat.h b/compat.h index 2a7003b5..582348a4 100644 --- a/compat.h +++ b/compat.h @@ -70,24 +70,29 @@ static inline int setpriority(__maybe_unused int which, __maybe_unused int who, return 0; } -//implement strsep() for windows -static char* strsep(char** stringp, const char* delim) +#ifndef HAVE_STRSEP +inline char *strsep(char **stringp, const char *delim) { - char* start = *stringp; - char* p; + char *res; - p = ((start != NULL)?strpbrk(start, delim):NULL); + if (!stringp || !*stringp || !**stringp) { + return NULL; + } + + res = *stringp; + while(**stringp && !strchr(delim, **stringp)) { + ++(*stringp); + } - if(p == NULL) - *stringp = NULL; - else - { - *p = '\0'; - *stringp = p + 1; + if (**stringp) { + **stringp = '\0'; + ++(*stringp); } - return start; + return res; } +#endif + typedef unsigned long int ulong; typedef unsigned short int ushort; diff --git a/winbuild/dist/include/winbuild.h b/winbuild/dist/include/winbuild.h index 014f8461..a5b5da07 100644 --- a/winbuild/dist/include/winbuild.h +++ b/winbuild/dist/include/winbuild.h @@ -1,6 +1,5 @@ -#ifndef __WINBUILD_H__ -#define __WINBUILD_H__ -#endif +#ifndef WINBUILD_H +#define WINBUILD_H #if defined(_MSC_VER) @@ -131,29 +130,6 @@ inline void* memmem (void* buf, size_t buflen, void* pat, size_t patlen) return 0; } -#ifndef HAVE_STRSEP -inline char *strsep(char **stringp, const char *delim) -{ - char *res; - - if (!stringp || !*stringp || !**stringp) { - return NULL; - } - - res = *stringp; - while(**stringp && !strchr(delim, **stringp)) { - ++(*stringp); - } - - if (**stringp) { - **stringp = '\0'; - ++(*stringp); - } - - return res; -} -#endif - #define va_copy(a, b) memcpy(&(a), &(b), sizeof(va_list)) #define usleep(x) Sleep((x)/1000) @@ -162,5 +138,5 @@ inline char *strsep(char **stringp, const char *delim) #define __func__ __FUNCTION__ #define __attribute__(x) - -#endif \ No newline at end of file +#endif /* _MSC_VER */ +#endif /* WINBUILD_H */