diff src/win32/libc_interface.c @ 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 10ffafd1c91f
children 86037d6bf80f
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 */
 
 /*