libdl: first execute all destructors, then munmap library
[uclibc-ng.git] / libc / string / strtok_r.c
blob2026888f8d3e8a304fad259a50ab460e4f7a99b5
1 /*
2 * Copyright (C) 2002 Manuel Novoa III
3 * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
5 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
6 */
8 #include "_string.h"
10 #ifdef WANT_WIDE
11 # define Wstrtok_r wcstok
12 # define Wstrspn wcsspn
13 # define Wstrpbrk wcspbrk
14 #else
15 # define Wstrtok_r strtok_r
16 # define Wstrspn strspn
17 # define Wstrpbrk strpbrk
18 #endif
20 Wchar *Wstrtok_r(Wchar * __restrict s1, const Wchar * __restrict s2,
21 Wchar ** __restrict next_start)
23 register Wchar *s;
24 register Wchar *p;
26 #if 1
27 if (((s = s1) != NULL) || ((s = *next_start) != NULL)) {
28 if (*(s += Wstrspn(s, s2))) {
29 if ((p = Wstrpbrk(s, s2)) != NULL) {
30 *p++ = 0;
32 } else {
33 p = s = NULL;
35 *next_start = p;
37 return s;
38 #else
39 if (!(s = s1)) {
40 s = *next_start;
42 if (s && *(s += Wstrspn(s, s2))) {
43 if (*(p = s + Wstrcspn(s, s2))) {
44 *p++ = 0;
46 *next_start = p;
47 return s;
49 return NULL; /* TODO: set *next_start = NULL for safety? */
50 #endif
53 #ifndef WANT_WIDE
54 libc_hidden_def(strtok_r)
55 #endif