Mercurial > pidgin
changeset 4193:c297b9d4f67c
[gaim-migrate @ 4424]
strsep
committer: Tailor Script <tailor@pidgin.im>
author | Herman Bloggs <hermanator12002@yahoo.com> |
---|---|
date | Fri, 03 Jan 2003 20:51:08 +0000 |
parents | 17187504bfc2 |
children | 9325df841a40 |
files | src/win32/libc_interface.c src/win32/libc_interface.h |
diffstat | 2 files changed, 45 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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 */ /*
--- 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 */