]> git.sesse.net Git - vlc/commitdiff
Implemented strsep replacement.
authorLaurent Aimar <fenrir@videolan.org>
Wed, 3 Sep 2008 19:07:12 +0000 (21:07 +0200)
committerLaurent Aimar <fenrir@videolan.org>
Wed, 3 Sep 2008 19:07:12 +0000 (21:07 +0200)
include/vlc_common.h
include/vlc_fixups.h
src/extras/libc.c

index 52d01ca657a82e4eecf40c39ddf7b1a6dd893f85..66550db4ffb8cf17db8308a4d454bf8a8bc0572d 100644 (file)
@@ -755,6 +755,7 @@ VLC_EXPORT( size_t, vlc_strlcpy, ( char *, const char *, size_t ) );
 VLC_EXPORT( long long, vlc_strtoll, ( const char *nptr, char **endptr, int base ) );
 
 VLC_EXPORT( char *, vlc_strcasestr, ( const char *s1, const char *s2 ) );
+VLC_EXPORT( char *, vlc_strsep, ( char **, const char * ) );
 
 #if defined(WIN32) || defined(UNDER_CE)
 /* win32, cl and icl support */
index df250fc81876a12b51f7a4e163606d48b00277ba..11e279f8055f52ae8df6aae9c66beee10326b484 100644 (file)
@@ -108,6 +108,10 @@ static inline char *strndup (const char *str, size_t max)
 # define strtoll vlc_strtoll
 #endif
 
+#ifndef HAVE_STRSEP
+# define strsep vlc_strsep
+#endif
+
 #ifndef HAVE_ATOLL
 # define atoll( str ) (strtoll ((str), (char **)NULL, 10))
 #endif
index f58f05fe77899f3a59d67608bdb0a739a575fd55..f20b8a31d5b4e0385d15a72f11c55d708e4814f5 100644 (file)
@@ -208,6 +208,28 @@ extern size_t vlc_strlcpy (char *tgt, const char *src, size_t bufsize)
 #endif
 }
 
+/**
+ * Extract a token from string.
+ * It is a replacement for strsep if not present.
+ */
+char *vlc_strsep( char **ppsz_string, const char *psz_delimiters )
+{
+    char *psz_string = *ppsz_string;
+    if( !psz_string )
+        return NULL;
+
+    char *p = strpbrk( psz_string, psz_delimiters );
+    if( !p )
+    {
+        *ppsz_string = NULL;
+        return psz_string;
+    }
+    *p++ = '\0';
+
+    *ppsz_string = p;
+    return psz_string;
+}
+
 /*****************************************************************************
  * vlc_*dir_wrapper: wrapper under Windows to return the list of drive letters
  * when called with an empty argument or just '\'