[vlc-devel] commit: Implemented strsep replacement. (Laurent Aimar )

git version control git at videolan.org
Wed Sep 3 21:05:03 CEST 2008


vlc | branch: master | Laurent Aimar <fenrir at videolan.org> | Wed Sep  3 21:07:12 2008 +0200| [e2123909a9be46a704bc922ae9cf0a0a50040cc8] | committer: Laurent Aimar 

Implemented strsep replacement.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e2123909a9be46a704bc922ae9cf0a0a50040cc8
---

 include/vlc_common.h |    1 +
 include/vlc_fixups.h |    4 ++++
 src/extras/libc.c    |   22 ++++++++++++++++++++++
 3 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/include/vlc_common.h b/include/vlc_common.h
index 52d01ca..66550db 100644
--- a/include/vlc_common.h
+++ b/include/vlc_common.h
@@ -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 */
diff --git a/include/vlc_fixups.h b/include/vlc_fixups.h
index df250fc..11e279f 100644
--- a/include/vlc_fixups.h
+++ b/include/vlc_fixups.h
@@ -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
diff --git a/src/extras/libc.c b/src/extras/libc.c
index f58f05f..f20b8a3 100644
--- a/src/extras/libc.c
+++ b/src/extras/libc.c
@@ -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 '\'




More information about the vlc-devel mailing list