OSDN Git Service

hidden_def/hidden_proto: convert all users (I hope) termios split, add some missing...
[uclinux-h8/uClibc.git] / libc / string / strtok_r.c
1 /*
2  * Copyright (C) 2002     Manuel Novoa III
3  * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
4  *
5  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
6  */
7
8 #include "_string.h"
9
10 #ifdef WANT_WIDE
11 libc_hidden_proto(wcsspn)
12 libc_hidden_proto(wcspbrk)
13 # define Wstrtok_r wcstok
14 # define Wstrspn wcsspn
15 # define Wstrpbrk wcspbrk
16 #else
17 libc_hidden_proto(strtok_r)
18 libc_hidden_proto(strspn)
19 libc_hidden_proto(strpbrk)
20 # define Wstrtok_r strtok_r
21 # define Wstrspn strspn
22 # define Wstrpbrk strpbrk
23 #endif
24
25 Wchar *Wstrtok_r(Wchar * __restrict s1, const Wchar * __restrict s2,
26                                  Wchar ** __restrict next_start)
27 {
28         register Wchar *s;
29         register Wchar *p;
30
31 #if 1
32         if (((s = s1) != NULL) || ((s = *next_start) != NULL)) {
33                 if (*(s += Wstrspn(s, s2))) {
34                         if ((p = Wstrpbrk(s, s2)) != NULL) {
35                                 *p++ = 0;
36                         }
37                 } else {
38                         p = s = NULL;
39                 }
40                 *next_start = p;
41         }
42         return s;
43 #else
44         if (!(s = s1)) {
45                 s = *next_start;
46         }
47         if (s && *(s += Wstrspn(s, s2))) {
48                 if (*(p = s + Wstrcspn(s, s2))) {
49                         *p++ = 0;
50                 }
51                 *next_start = p;
52                 return s;
53         }
54         return NULL;                            /* TODO: set *next_start = NULL for safety? */
55 #endif
56 }
57
58 #ifndef WANT_WIDE
59 libc_hidden_def(strtok_r)
60 #endif