summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2002-05-07 07:42:30 +0000
committerDaniel Stenberg <daniel@haxx.se>2002-05-07 07:42:30 +0000
commita037f0c226606d8c29f0cbbf991e6eed1998f02a (patch)
treeaf34e15b4347ad919f6d198f1799655f4b49609f
parent5993f56007172ebce70e62697770655e7645304b (diff)
downloadrockbox-a037f0c226606d8c29f0cbbf991e6eed1998f02a.tar.gz
rockbox-a037f0c226606d8c29f0cbbf991e6eed1998f02a.zip
strtok_r() freshly implemented by yours truly
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@486 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/common/strtok.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/firmware/common/strtok.c b/firmware/common/strtok.c
new file mode 100644
index 0000000000..10287749c1
--- /dev/null
+++ b/firmware/common/strtok.c
@@ -0,0 +1,67 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Daniel Stenberg
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied. *
17 ****************************************************************************/
18
19#include "config.h"
20
21#ifndef HAVE_STRTOK_R
22#include <stddef.h>
23#include <string.h>
24
25char *
26strtok_r(char *ptr, const char *sep, char **end)
27{
28 if (!ptr)
29 /* we got NULL input so then we get our last position instead */
30 ptr = *end;
31
32 /* pass all letters that are including in the separator string */
33 while (*ptr && strchr(sep, *ptr))
34 ++ptr;
35
36 if (*ptr) {
37 /* so this is where the next piece of string starts */
38 char *start = ptr;
39
40 /* set the end pointer to the first byte after the start */
41 *end = start + 1;
42
43 /* scan through the string to find where it ends, it ends on a
44 null byte or a character that exists in the separator string */
45 while (**end && !strchr(sep, **end))
46 ++*end;
47
48 if (**end) {
49 /* the end is not a null byte */
50 **end = '\0'; /* zero terminate it! */
51 ++*end; /* advance last pointer to beyond the null byte */
52 }
53
54 return start; /* return the position where the string starts */
55 }
56
57 /* we ended up on a null byte, there are no more strings to find! */
58 return NULL;
59}
60
61#endif /* this was only compiled if strtok_r wasn't present */
62
63/*
64 * local variables:
65 * eval: (load-file "../rockbox-mode.el")
66 * end:
67 */