Revision: 14584
Author: adrian.chadd
Date: Sun Apr 11 03:53:57 2010
Log: Issue #94 - add strsep for platforms don't have it - eg native windows


http://code.google.com/p/lusca-cache/source/detail?r=14584

Added:
 /branches/LUSCA_HEAD/lib/strsep.c
Modified:
 /branches/LUSCA_HEAD/include/strsep.h
 /branches/LUSCA_HEAD/lib/Makefile.am

=======================================
--- /dev/null
+++ /branches/LUSCA_HEAD/lib/strsep.c   Sun Apr 11 03:53:57 2010
@@ -0,0 +1,79 @@
+/*-
+ * Copyright (c) 1990, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+__FBSDID("$FreeBSD: stable/8/lib/libc/string/strsep.c 188080 2009-02-03 17:58:20Z danger $");
+*/
+
+#include "../include/config.h"
+
+#ifndef HAVE_STRSEP
+
+#include <string.h>
+#include <stdio.h>
+
+/*
+ * Get next token from string *stringp, where tokens are possibly-empty
+ * strings separated by characters from delim.
+ *
+ * Writes NULs into the string at *stringp to end tokens.
+ * delim need not remain constant from call to call.
+ * On return, *stringp points past the last NUL written (if there might
+ * be further tokens), or is NULL (if there are definitely no more tokens).
+ *
+ * If *stringp is NULL, strsep returns NULL.
+ */
+char *
+strsep(char **stringp, const char *delim)
+{
+       char *s;
+       const char *spanp;
+       int c, sc;
+       char *tok;
+
+       if ((s = *stringp) == NULL)
+               return (NULL);
+       for (tok = s;;) {
+               c = *s++;
+               spanp = delim;
+               do {
+                       if ((sc = *spanp++) == c) {
+                               if (c == 0)
+                                       s = NULL;
+                               else
+                                       s[-1] = 0;
+                               *stringp = s;
+                               return (tok);
+                       }
+               } while (sc != 0);
+       }
+       /* NOTREACHED */
+}
+
+#endif /* HAVE_STRSEP */
=======================================
--- /branches/LUSCA_HEAD/include/strsep.h       Sun May 21 02:40:31 2006
+++ /branches/LUSCA_HEAD/include/strsep.h       Sun Apr 11 03:53:57 2010
@@ -1,24 +1,5 @@
-/* Copyright (C) 2004 Free Software Foundation, Inc.
- * Written by Yoann Vandoorselaere <[email protected]>
- *
- * The file is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This file is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this file; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA.
- */
-
-#ifndef GNULIB_STRSEP_H_
-#define GNULIB_STRSEP_H_
+#ifndef _LUSCA_STRSEP_H_
+#define _LUSCA_STRSEP_H_

 #if HAVE_STRSEP

@@ -29,25 +10,9 @@

 #else

-/* Searches the next delimiter (char listed in DELIM) starting at *STRINGP.
-   If one is found, it is overwritten with a NUL, and *STRINGP is advanced
-   to point to the next char after it.  Otherwise, *STRINGP is set to NULL.
-   If *STRINGP was already NULL, nothing happens.
-   Returns the old value of *STRINGP.
-
-   This is a variant of strtok() that is multithread-safe and supports
-   empty fields.
-
-   Caveat: It modifies the original string.
-   Caveat: These functions cannot be used on constant strings.
-   Caveat: The identity of the delimiting character is lost.
- Caveat: It doesn't work with multibyte strings unless all of the delimiter
-           characters are ASCII characters < 0x30.
-
-   See also strtok_r().  */
-
-extern char *strsep (char **stringp, const char *delim);
+/* strsep() definition from the FreeBSD libc strsep */
+extern char *strsep (char **, const char *);

 #endif

-#endif /* GNULIB_STRSEP_H_ */
+#endif /* _LUSCA_STRSEP_H_ */
=======================================
--- /branches/LUSCA_HEAD/lib/Makefile.am        Sat Apr 10 04:24:15 2010
+++ /branches/LUSCA_HEAD/lib/Makefile.am        Sun Apr 11 03:53:57 2010
@@ -53,6 +53,7 @@
        rfc2617.c \
        safe_inet_addr.c \
        splay.c \
+       strsep.c \
        Stack.c \
        stub_memaccount.c \
        util.c \

--
You received this message because you are subscribed to the Google Groups 
"lusca-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/lusca-commit?hl=en.

Reply via email to