1/* Reentrant string tokenizer. Generic version.
2 Copyright (C) 1991,1996-1999,2001,2004 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
19
20/* Copyright (C) 1991,93,96,97,99,2000,2002 Free Software Foundation, Inc.
21 This file is part of the GNU C Library.
22 Based on strlen implementation by Torbjorn Granlund (tege@sics.se),
23 with help from Dan Sahlin (dan@sics.se) and
24 commentary by Jim Blandy (jimb@ai.mit.edu);
25 adaptation to memchr suggested by Dick Karpinski (dick@cca.ucsf.edu),
26 and implemented by Roland McGrath (roland@ai.mit.edu).
27
28 The GNU C Library is free software; you can redistribute it and/or
29 modify it under the terms of the GNU Lesser General Public
30 License as published by the Free Software Foundation; either
31 version 2.1 of the License, or (at your option) any later version.
32
33 The GNU C Library is distributed in the hope that it will be useful,
34 but WITHOUT ANY WARRANTY; without even the implied warranty of
35 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
36 Lesser General Public License for more details.
37
38 You should have received a copy of the GNU Lesser General Public
39 License along with the GNU C Library; if not, write to the Free
40 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
41 02111-1307 USA. */
42
43//========================================================================
44//
45// Modified under the Poppler project - http://poppler.freedesktop.org
46//
47// All changes made under the Poppler project to this file are licensed
48// under GPL version 2 or later
49//
50// Copyright (C) 2012 Alexey Pavlov <alexpux@gmail.com>
51// Copyright (C) 2012 Albert Astals Cid <aacid@kde.org>
52// Copyright (C) 2017 Adrian Johnson <ajohnson@redneon.com>
53// Copyright (C) 2017 Pekka Vuorela <pekka.vuorela@jollamobile.com>
54//
55// To see a description of the changes please see the Changelog file that
56// came with your tarball or type make ChangeLog if you are building from git
57//
58//========================================================================
59
60#include "glibc.h"
61
62#ifndef HAVE_STRTOK_R
63
64# include <cstring>
65
66# define __rawmemchr strchr
67
68char *strtok_r(char *s, const char *delim, char **save_ptr)
69{
70 char *token;
71
72 if (s == NULL)
73 s = *save_ptr;
74
75 /* Scan leading delimiters. */
76 s += strspn(s, delim);
77 if (*s == '\0') {
78 *save_ptr = s;
79 return NULL;
80 }
81
82 /* Find the end of the token. */
83 token = s;
84 s = strpbrk(token, delim);
85 if (s == NULL)
86 /* This token finishes the string. */
87 *save_ptr = __rawmemchr(token, '\0');
88 else {
89 /* Terminate the token and make *SAVE_PTR point past it. */
90 *s = '\0';
91 *save_ptr = s + 1;
92 }
93 return token;
94}
95
96#endif
97

source code of poppler/goo/glibc_strtok_r.cc