# HG changeset patch # User Herman Bloggs # Date 1041627068 0 # Node ID c297b9d4f67cc321626d8bea64c2c46bd8feac9c # Parent 17187504bfc2f3e4957f385137e2303f6a3abfdd [gaim-migrate @ 4424] strsep committer: Tailor Script diff -r 17187504bfc2 -r c297b9d4f67c src/win32/libc_interface.c --- a/src/win32/libc_interface.c Fri Jan 03 20:49:12 2003 +0000 +++ b/src/win32/libc_interface.c Fri Jan 03 20:51:08 2003 +0000 @@ -168,6 +168,47 @@ return strerror( errornum ); } +/* From glibc 2.2.5 */ +char* wgaim_strsep(char **stringp, const char *delim) { + char *begin, *end; + + begin = *stringp; + if (begin == NULL) + return NULL; + + /* A frequent case is when the delimiter string contains only one + character. Here we don't need to call the expensive `strpbrk' + function and instead work using `strchr'. */ + if (delim[0] == '\0' || delim[1] == '\0') { + char ch = delim[0]; + + if (ch == '\0') + end = NULL; + else { + if (*begin == ch) + end = begin; + else if (*begin == '\0') + end = NULL; + else + end = strchr (begin + 1, ch); + } + } + else + /* Find the end of the token. */ + end = strpbrk (begin, delim); + + if (end) { + /* Terminate the token and set *STRINGP past NUL character. */ + *end++ = '\0'; + *stringp = end; + } + else + /* No more delimiters; this is the last token. */ + *stringp = NULL; + + return begin; +} + /* unistd.h */ /* diff -r 17187504bfc2 -r c297b9d4f67c src/win32/libc_interface.h --- a/src/win32/libc_interface.h Fri Jan 03 20:49:12 2003 +0000 +++ b/src/win32/libc_interface.h Fri Jan 03 20:51:08 2003 +0000 @@ -50,6 +50,10 @@ #define strerror( errornum ) \ wgaim_strerror( ## errornum ## ) +extern char* wgaim_strsep(char **stringp, const char *delim); +#define strsep( stringp, delim ) \ +wgaim_strsep( ## stringp ##, ## delim ## ) + #define bzero( dest, size ) memset( ## dest ##, 0, ## size ## ) /* unistd.h */