blob: 2026888f8d3e8a304fad259a50ab460e4f7a99b5 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/*
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# 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
19
20Wchar *Wstrtok_r(Wchar * __restrict s1, const Wchar * __restrict s2,
21 Wchar ** __restrict next_start)
22{
23 register Wchar *s;
24 register Wchar *p;
25
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;
31 }
32 } else {
33 p = s = NULL;
34 }
35 *next_start = p;
36 }
37 return s;
38#else
39 if (!(s = s1)) {
40 s = *next_start;
41 }
42 if (s && *(s += Wstrspn(s, s2))) {
43 if (*(p = s + Wstrcspn(s, s2))) {
44 *p++ = 0;
45 }
46 *next_start = p;
47 return s;
48 }
49 return NULL; /* TODO: set *next_start = NULL for safety? */
50#endif
51}
52
53#ifndef WANT_WIDE
54libc_hidden_def(strtok_r)
55#endif