summaryrefslogtreecommitdiffstats
path: root/lib/strsep.c
diff options
context:
space:
mode:
authorGreg McGary <greg@mcgary.org>1999-04-12 07:56:55 +0000
committerGreg McGary <greg@mcgary.org>1999-04-12 07:56:55 +0000
commita05ba261e9c40c9ef95b286d7a8abff519551295 (patch)
treea6ba2a8343cfcc9838e52b5ef4a75c238c8598b7 /lib/strsep.c
parent258a961c23341294b12a317ad6534b30ad02d987 (diff)
downloadidutils-a05ba261e9c40c9ef95b286d7a8abff519551295.tar.gz
idutils-a05ba261e9c40c9ef95b286d7a8abff519551295.tar.bz2
idutils-a05ba261e9c40c9ef95b286d7a8abff519551295.zip
* lib/strsep.c: Add file.
* lib/strtok.c: Remove file. * configure.in: Check for strsep instead of strtok. * libidu/idfile.c (locate_id_file_name): Use strsep instead of strtok. * libidu/scanners.c (language_save_arg, language_save_arg, tokenize_args_string): Ditto. * libidu/walker.c (append_strings_to_vector, vectorize_string): Ditto.
Diffstat (limited to 'lib/strsep.c')
-rw-r--r--lib/strsep.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/lib/strsep.c b/lib/strsep.c
new file mode 100644
index 0000000..a118b1b
--- /dev/null
+++ b/lib/strsep.c
@@ -0,0 +1,62 @@
+/* Copyright (C) 1992, 1993, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <string.h>
+
+char *
+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
+ 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;
+}