fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / gcc / newlib / libc / string / strtok.c
blob8d53290c71f03d7c92f2d7c6aaf9ae5a63b1ecbc
1 /*
2 FUNCTION
3 <<strtok>>,<<strtok_r>>,<<strsep>>---get next token from a string
5 INDEX
6 strtok
8 INDEX
9 strtok_r
11 INDEX
12 strsep
14 ANSI_SYNOPSIS
15 #include <string.h>
16 char *strtok(char *<[source]>, const char *<[delimiters]>)
17 char *strtok_r(char *<[source]>, const char *<[delimiters]>,
18 char **<[lasts]>)
19 char *strsep(char **<[source_ptr]>, const char *<[delimiters]>)
21 TRAD_SYNOPSIS
22 #include <string.h>
23 char *strtok(<[source]>, <[delimiters]>)
24 char *<[source]>;
25 char *<[delimiters]>;
27 char *strtok_r(<[source]>, <[delimiters]>, <[lasts]>)
28 char *<[source]>;
29 char *<[delimiters]>;
30 char **<[lasts]>;
32 char *strsep(<[source_ptr]>, <[delimiters]>)
33 char **<[source_ptr]>;
34 char *<[delimiters]>;
36 DESCRIPTION
37 The <<strtok>> function is used to isolate sequential tokens in a
38 null-terminated string, <<*<[source]>>>. These tokens are delimited
39 in the string by at least one of the characters in <<*<[delimiters]>>>.
40 The first time that <<strtok>> is called, <<*<[source]>>> should be
41 specified; subsequent calls, wishing to obtain further tokens from
42 the same string, should pass a null pointer instead. The separator
43 string, <<*<[delimiters]>>>, must be supplied each time, and may
44 change between calls.
46 The <<strtok>> function returns a pointer to the beginning of each
47 subsequent token in the string, after replacing the separator
48 character itself with a NUL character. When no more tokens remain,
49 a null pointer is returned.
51 The <<strtok_r>> function has the same behavior as <<strtok>>, except
52 a pointer to placeholder <<*[lasts]>> must be supplied by the caller.
54 The <<strsep>> function is similar in behavior to <<strtok>>, except
55 a pointer to the string pointer must be supplied <<[source_ptr]>> and
56 the function does not skip leading delimeters. When the string starts
57 with a delimeter, the delimeter is changed to the NUL character and
58 the empty string is returned. Like <<strtok_r>> and <<strtok>>, the
59 <<*[source_ptr]>> is updated to the next character following the
60 last delimeter found or NULL if the end of string is reached with
61 no more delimeters.
63 RETURNS
64 <<strtok>>, <<strtok_r>>, and <<strsep>> all return a pointer to the
65 next token, or <<NULL>> if no more tokens can be found. For
66 <<strsep>>, a token may be the empty string.
68 NOTES
69 <<strtok>> is unsafe for multi-thread applications. <<strtok_r>>
70 and <<strsep>> are MT-Safe and should be used instead.
72 PORTABILITY
73 <<strtok>> is ANSI C.
74 <<strtok_r>> is POSIX.
75 <<strsep>> is a BSD-extension.
77 <<strtok>>, <<strtok_r>>, and <<strsep>> require no supporting OS subroutines.
79 QUICKREF
80 strtok ansi impure
83 /* undef STRICT_ANSI so that strtok_r prototype will be defined */
84 #undef __STRICT_ANSI__
85 #include <string.h>
86 #include <_ansi.h>
87 #include <reent.h>
89 #ifndef _REENT_ONLY
91 extern char *__strtok_r (char *, const char *, char **, int);
93 char *
94 _DEFUN (strtok, (s, delim),
95 register char *s _AND
96 register const char *delim)
98 _REENT_CHECK_MISC(_REENT);
99 return __strtok_r (s, delim, &(_REENT_STRTOK_LAST(_REENT)), 1);
101 #endif