3841 strnstr() needs a man page
[unleashed.git] / usr / src / man / man3c / string.3c
blob145fc54ea145125e7562473bba5eabafd698dc80
1 '\" te
2 .\" Copyright 2014 Garrett D'Amore <garrett@damore.org>
3 .\" Copyright (c) 2014, Joyent, Inc.
4 .\" Copyright (c) 2008, Sun Microsystems, Inc.  All Rights Reserved.
5 .\" Copyright 1989 AT&T
6 .\" Portions Copyright (c) 1994 Man-cgi 1.15, Panagiotis Christias (christia@softlab.ntua.gr)
7 .\" Portions Copyright (c) 1996-2008 Modified for NetBSD by Kimmo Suominen (kimmo@suominen.com)
8 .\" Portions Copyright (c) 1992, X/Open Company Limited.  All Rights Reserved.
9 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
10 .\" http://www.opengroup.org/bookstore/.
11 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
12 .\"  This notice shall appear on any product containing this material.
13 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
14 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
15 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
16 .TH STRING 3C "Jun 21, 2013"
17 .SH NAME
18 string, strcasecmp, strcasecmp_l, strncasecmp, strncasecmp_l, strcat, strncat,
19 strlcat, strchr, strrchr,
20 strcmp, strncmp, strcpy, strncpy, strlcpy, strcspn, strspn, strdup, strlen,
21 strnlen, strpbrk, strsep, strstr, strnstr, strtok, strtok_r \- string operations
22 .SH SYNOPSIS
23 .LP
24 .nf
25 #include <strings.h>
27 \fBint\fR \fBstrcasecmp\fR(\fBconst char *\fR\fIs1\fR, \fBconst char *\fR\fIs2\fR);
28 .fi
29 .LP
30 .nf
31 \fBint\fR \fBstrcasecmp_l\fR(\fBconst char *\fR\fIs1\fR, \fBconst char *\fR\fIs2\fR, \fBlocale_t\fR \fIloc\fR);
32 .fi
33 .LP
34 .nf
35 \fBint\fR \fBstrncasecmp\fR(\fBconst char *\fR\fIs1\fR, \fBconst char *\fR\fIs2\fR, \fBsize_t\fR \fIn\fR);
36 .fi
37 .LP
38 .nf
39 \fBint\fR \fBstrncasecmp_l\fR(\fBconst char *\fR\fIs1\fR, \fBconst char *\fR\fIs2\fR, \fBsize_t\fR \fIn\fR, \fBlocale_t\fR \fIloc\fR);
40 .fi
41 .LP
42 .nf
43 #include <string.h>
45 \fBchar *\fR\fBstrcat\fR(\fBchar *restrict\fR \fIs1\fR, \fBconst char *restrict\fR \fIs2\fR);
46 .fi
47 .LP
48 .nf
49 \fBchar *\fR\fBstrncat\fR(\fBchar *restrict\fR \fIs1\fR, \fBconst char *restrict\fR \fIs2\fR, \fBsize_t\fR \fIn\fR);
50 .fi
51 .LP
52 .nf
53 \fBsize_t\fR \fBstrlcat\fR(\fBchar *\fR\fIdst\fR, \fBconst char *\fR\fIsrc\fR, \fBsize_t\fR \fIdstsize\fR);
54 .fi
55 .LP
56 .nf
57 \fBchar *\fR\fBstrchr\fR(\fBconst char *\fR\fIs\fR, \fBint\fR \fIc\fR);
58 .fi
59 .LP
60 .nf
61 \fBchar *\fR\fBstrrchr\fR(\fBconst char *\fR\fIs\fR, \fBint\fR \fIc\fR);
62 .fi
63 .LP
64 .nf
65 \fBint\fR \fBstrcmp\fR(\fBconst char *\fR\fIs1\fR, \fBconst char *\fR\fIs2\fR);
66 .fi
67 .LP
68 .nf
69 \fBint\fR \fBstrncmp\fR(\fBconst char *\fR\fIs1\fR, \fBconst char *\fR\fIs2\fR, \fBsize_t\fR \fIn\fR);
70 .fi
71 .LP
72 .nf
73 \fBchar *\fR\fBstrcpy\fR(\fBchar *restrict\fR \fIs1\fR, \fBconst char *restrict\fR \fIs2\fR);
74 .fi
75 .LP
76 .nf
77 \fBchar *\fR\fBstrncpy\fR(\fBchar *restrict\fR \fIs1\fR, \fBconst char *restrict\fR \fIs2\fR, \fBsize_t\fR \fIn\fR);
78 .fi
79 .LP
80 .nf
81 \fBsize_t\fR \fBstrlcpy\fR(\fBchar *\fR\fIdst\fR, \fBconst char *\fR\fIsrc\fR, \fBsize_t\fR \fIdstsize\fR);
82 .fi
83 .LP
84 .nf
85 \fBsize_t\fR \fBstrcspn\fR(\fBconst char *\fR\fIs1\fR, \fBconst char *\fR\fIs2\fR);
86 .fi
87 .LP
88 .nf
89 \fBsize_t\fR \fBstrspn\fR(\fBconst char *\fR\fIs1\fR, \fBconst char *\fR\fIs2\fR);
90 .fi
91 .LP
92 .nf
93 \fBchar *\fR\fBstrdup\fR(\fBconst char *\fR\fIs1\fR);
94 .fi
95 .LP
96 .nf
97 \fBsize_t\fR \fBstrlen\fR(\fBconst char *\fR\fIs\fR);
98 .fi
99 .LP
101 \fBsize_t\fR \fBstrnlen\fR(\fBconst char *\fR\fIs\fR, \fBsize_t\fR \fIn\fR);
105 \fBchar *\fR\fBstrpbrk\fR(\fBconst char *\fR\fIs1\fR, \fBconst char *\fR\fIs2\fR);
109 \fBchar *\fR\fBstrsep\fR(\fBchar **\fR\fIstringp\fR, \fBconst char *\fR\fIdelim\fR);
113 \fBchar *\fR\fBstrstr\fR(\fBconst char *\fR\fIs1\fR, \fBconst char *\fR\fIs2\fR);
117 \fBchar *\fR\fBstrnstr\fR(\fBconst char *\fR\fIs1\fR, \fBconst char *\fR\fIs2\fR, \fBsize_t\fR \fIn\fR);
121 \fBchar *\fR\fBstrtok\fR(\fBchar *restrict\fR \fIs1\fR, \fBconst char *restrict\fR \fIs2\fR);
125 \fBchar *\fR\fBstrtok_r\fR(\fBchar *restrict\fR \fIs1\fR, \fBconst char *restrict\fR \fIs2\fR,
126      \fBchar **restrict\fR \fIlasts\fR);
128 .SS "ISO C++"
131 #include <string.h>
133 \fBconst char *\fR\fBstrchr\fR(\fBconst char *\fR\fIs\fR, \fBint\fR \fIc\fR);
137 \fBconst char *\fR\fBstrpbrk\fR(\fBconst char *\fR\fIs1\fR, \fBconst char *\fR\fIs2\fR);
141 \fBconst char *\fR\fBstrrchr\fR(\fBconst char *\fR\fIs\fR, \fBint\fR \fIc\fR);
145 \fBconst char *\fR\fBstrstr\fR(\fBconst char *\fR\fIs1\fR, \fBconst char *\fR\fIs2\fR);
149 #include <cstring>
151 \fBchar *std::\fR\fBstrchr\fR(\fBchar *\fR\fIs\fR, \fBint\fR \fIc\fR);
155 \fBchar *std::\fR\fBstrpbrk\fR(\fBchar *\fR\fIs1\fR, \fBconst char *\fR\fIs2\fR);
159 \fBchar *std::\fR\fBstrrchr\fR(\fBchar *\fR\fIs\fR, \fBint\fR \fIc\fR);
163 \fBchar *std::\fR\fBstrstr\fR(\fBchar *\fR\fIs1\fR, \fBconst char *\fR\fIs2\fR);
165 .SH DESCRIPTION
167 The arguments \fIs\fR, \fIs1\fR, and \fIs2\fR point to strings (arrays of
168 characters terminated by a null character). The \fBstrcat()\fR,
169 \fBstrncat()\fR, \fBstrlcat()\fR, \fBstrcpy()\fR, \fBstrncpy()\fR,
170 \fBstrlcpy()\fR, \fBstrsep()\fR, \fBstrtok()\fR, and \fBstrtok_r()\fR functions
171 all alter their first argument. Additionally, the \fBstrcat()\fR and
172 \fBstrcpy()\fR functions do not check for overflow of the array.
173 .SS "\fBstrcasecmp()\fR, \fBstrncasecmp()\fR"
175 The \fBstrcasecmp()\fR and \fBstrncasecmp()\fR functions are case-insensitive
176 versions of  \fBstrcmp()\fR and \fBstrncmp()\fR respectively, described below.
178 The \fBstrcasecmp()\fR and \fBstrncasecmp()\fR functions compare two strings
179 byte-by-byte, after
180 converting each upper-case character to lower-case (as determined by the
181 \fBLC_CTYPE\fR category of the current locale).  Note that neither the contents
182 pointed to by \fIs1\fR nor \fIs2\fR are modified.
184 The functions return an integer
185 greater than, equal to, or less than 0, if the string pointed to by \fIs1\fR
186 is greater than, equal to, or less than the string pointed to by \fIs2\fR
187 respectively. The sign of a non-zero return value is determined  by the sign of
188 the difference between the values of the first pair of bytes that differ in the
190 The \fBstrncasecmp()\fR function examines at most \fIn\fR bytes from each
191 string.
192 .SS "\fBstrcasecmp_l()\fR, \fBstrncasecmp_l()\fR"
194 The \fBstrcasecmp_l()\fR and \fBstrncasecmp_l()\fR functions behave identically
195 to \fBstrcasecmp()\fR and \fBstrncasecmp()\fR, except instead of operating in
196 the current locale, they instead operate in the locale specified by \fIloc\fR.
197 .SS "\fBstrcat()\fR, \fBstrncat()\fR, \fBstrlcat()\fR"
199 The \fBstrcat()\fR function appends a copy of string \fIs2\fR, including the
200 terminating null character, to the end of string \fIs1\fR. The \fBstrncat()\fR
201 function appends at most \fIn\fR characters. Each returns a pointer to the
202 null-terminated result. The initial character of  \fIs2\fR overrides the null
203 character at the end of \fIs1\fR. If copying takes place between objects that
204 overlap, the behavior of \fBstrcat()\fR, \fBstrncat()\fR, and \fBstrlcat()\fR
205 is undefined.
207 The \fBstrlcat()\fR function appends  at most
208 (\fIdstsize\fR-\fBstrlen\fR(\fIdst\fR)-1) characters of \fIsrc\fR to \fIdst\fR
209 (\fIdstsize\fR being the  size of the  string buffer \fIdst\fR). If the string
210 pointed to by \fIdst\fR contains a null-terminated string that fits into
211 \fIdstsize\fR bytes when \fBstrlcat()\fR is called, the string pointed to by
212 \fIdst\fR will be a null-terminated string that fits in \fIdstsize\fR bytes
213 (including the terminating null character) when it completes, and the initial
214 character of \fIsrc\fR will override the null character at  the end of
215 \fIdst\fR. If the string pointed to by \fIdst\fR is longer than \fIdstsize\fR
216 bytes when \fBstrlcat()\fR is called, the string pointed to by \fIdst\fR will
217 not be changed. The function returns
218 \fBmin\fR{\fIdstsize\fR,\fBstrlen\fR(\fIdst\fR)}+\fBstrlen\fR(\fIsrc\fR).
219 Buffer overflow can be checked as  follows:
221 .in +2
223 if (strlcat(dst, src, dstsize) >= dstsize)
224         return \(mi1;
226 .in -2
227 .SS "\fBstrchr()\fR, \fBstrrchr()\fR"
229 The \fBstrchr()\fR function returns a pointer to the first occurrence of
230 \fIc\fR (converted to a  \fBchar\fR) in string \fIs\fR, or a null pointer if
231 \fIc\fR does not occur in the string. The \fBstrrchr()\fR function returns a
232 pointer to the last occurrence of \fIc\fR. The null character terminating a
233 string is considered to be part of the string.
234 .SS "\fBstrcmp()\fR, \fBstrncmp()\fR"
236 The \fBstrcmp()\fR function compares two strings byte-by-byte, according to the
237 ordering of your machine's character set.  The function returns an integer
238 greater than, equal to, or less than 0, if  the string pointed to by \fIs1\fR
239 is greater than, equal to, or less than the string pointed to by \fIs2\fR
240 respectively. The sign of a non-zero return value is determined  by the sign of
241 the difference between the values of the first pair of bytes that differ in the
242 strings being compared. The \fBstrncmp()\fR function makes the same comparison
243 but looks at a maximum of \fIn\fR bytes. Bytes following a null byte are not
244 compared.
245 .SS "\fBstrcpy()\fR, \fBstrncpy()\fR, \fBstrlcpy()\fR"
247 The \fBstrcpy()\fR function copies string \fIs2\fR to \fIs1\fR, including the
248 terminating null character, stopping after the null character has been copied.
249 The \fBstrncpy()\fR function copies exactly \fIn\fR bytes, truncating \fIs2\fR
250 or adding null characters to \fIs1\fR if necessary. The result will not be
251 null-terminated if the length of \fIs2\fR is \fIn\fR or more. Each function
252 returns \fIs1\fR.  If copying takes place between objects that overlap, the
253 behavior of \fBstrcpy()\fR, \fBstrncpy()\fR, and \fBstrlcpy()\fR is undefined.
255 The \fBstrlcpy()\fR function copies  at most \fIdstsize\fR\(mi1 characters
256 (\fIdstsize\fR being the  size of the  string buffer \fIdst\fR) from \fIsrc\fR
257 to \fIdst\fR,  truncating \fIsrc\fR if necessary.  The  result is always
258 null-terminated. The function returns \fBstrlen\fR(\fIsrc\fR). Buffer overflow
259 can be checked as  follows:
261 .in +2
263 if (strlcpy(dst, src, dstsize) >= dstsize)
264         return \(mi1;
266 .in -2
268 .SS "\fBstrcspn()\fR, \fBstrspn()\fR"
270 The \fBstrcspn()\fR function returns the length of the initial segment of
271 string \fIs1\fR that consists entirely of characters not from string \fIs2\fR.
272 The \fBstrspn()\fR function returns the length of the initial segment of string
273 \fIs1\fR that consists entirely of characters from string \fIs2\fR.
274 .SS "\fBstrdup()\fR"
276 The \fBstrdup()\fR function returns a pointer to a new string that is a
277 duplicate of the string pointed to by  \fIs1\fR. The returned pointer can be
278 passed to \fBfree()\fR. The space for the new string is obtained using
279 \fBmalloc\fR(3C). If the new string cannot be created, a null pointer is
280 returned and \fBerrno\fR may be set to \fBENOMEM\fR to indicate that the
281 storage space available is insufficient.
282 .SS "\fBstrlen()\fR, \fBstrnlen()\fR"
283 The \fBstrlen()\fR function returns the number of bytes in \fIs\fR, not
284 including the terminating null character.
286 The \fBstrnlen()\fR function returns the smaller of \fIn\fR or the number of
287 bytes in \fIs\fR, not including the terminating null character. The
288 \fBstrnlen()\fR function never examines more than \fIn\fR bytes of the string
289 pointed to by \fIs\fR.
290 .SS "\fBstrpbrk()\fR"
292 The \fBstrpbrk()\fR function returns a pointer to the first occurrence in
293 string \fIs1\fR of any character from string \fIs2\fR, or a null pointer if no
294 character from \fIs2\fR exists in \fIs1\fR.
295 .SS "\fBstrsep()\fR"
297 The \fBstrsep()\fR function locates, in the null-terminated string referenced
298 by *\fIstringp\fR, the first occurrence of any character in the string
299 \fIdelim\fR (or the terminating `\e0' character) and replaces it with a `\e0'.
300 The location of the next character after the delimiter character (or
301 \fINULL\fR, if the end of the string was reached) is stored in *\fIstringp\fR.
302 The original value of *\fIstringp\fR is returned.
304 An ``empty'' field (one caused by two adjacent delimiter characters) can be
305 detected by comparing the location referenced by the pointer returned by
306 \fBstrsep()\fR to `\e0'.
308 If *\fIstringp\fR is initially \fINULL\fR, \fBstrsep()\fR returns \fINULL\fR.
309 .SS "\fBstrstr()\fR, \fBstrnstr()\fR"
311 The \fBstrstr()\fR function locates the first occurrence of the string \fIs2\fR
312 (excluding the terminating null character) in string \fIs1\fR and returns a
313 pointer to the located string, or a null pointer if the string is not found. If
314 \fIs2\fR points to a string with zero length (that is, the string \fB""\fR),
315 the function returns  \fIs1\fR. The \fBstrnstr()\fR function performs the same
316 search as \fBstrstr()\fR, but only considers up to \fIn\fR bytes of \fIs1\fR.
317 Bytes following a null byte are not compared.
318 .SS "\fBstrtok()\fR"
320 A sequence of calls to \fBstrtok()\fR breaks the string pointed to by \fIs1\fR
321 into a sequence of tokens, each of which is delimited by a byte from the string
322 pointed to by \fIs2\fR. The first call in the sequence has \fIs1\fR as its
323 first argument, and is followed by calls with a null pointer as their first
324 argument. The separator string pointed to by \fIs2\fR can be different from
325 call to call.
327 The first call in the sequence searches the string pointed to by \fIs1\fR for
328 the first byte that is not contained in the current separator string pointed to
329 by \fIs2\fR. If no such byte is found, then there are no tokens in the string
330 pointed to by \fIs1\fR and \fBstrtok()\fR returns a null pointer. If such a
331 byte is found, it is the start of the first token.
333 The \fBstrtok()\fR function then searches from there for a byte that is
334 contained in the current separator string. If no such byte is found, the
335 current token extends to the end of the string pointed to by \fIs1\fR, and
336 subsequent searches for a token return a null pointer. If such a byte is found,
337 it is overwritten by a null byte that terminates the current token. The
338 \fBstrtok()\fR function saves a pointer to the following byte in
339 thread-specific data, from which the next search for a token starts.
341 Each subsequent call, with a null pointer as the value of the first argument,
342 starts searching from the saved pointer and behaves as described above.
344 See Example 1, 2, and 3 in the \fBEXAMPLES\fR section for examples of
345 \fBstrtok()\fR usage and the explanation in \fBNOTES\fR.
346 .SS "\fBstrtok_r()\fR"
348 The \fBstrtok_r()\fR function considers the null-terminated string \fIs1\fR as
349 a sequence of zero or more text tokens separated by spans of one or more
350 characters from the separator string \fIs2\fR. The argument \fIlasts\fR points
351 to a user-provided pointer which points to stored information necessary for
352 \fBstrtok_r()\fR to continue scanning the same string.
354 In the first call to \fBstrtok_r()\fR, \fIs1\fR points to a null-terminated
355 string, \fIs2\fR to a null-terminated string of separator characters, and the
356 value pointed to by \fIlasts\fR is ignored. The \fBstrtok_r()\fR function
357 returns a pointer to the first character of the first token, writes a null
358 character into \fIs1\fR immediately following the returned token, and updates
359 the pointer to which \fIlasts\fR points.
361 In subsequent calls, \fIs1\fR is a null pointer and \fIlasts\fR is unchanged
362 from the previous call so that subsequent calls move through the string
363 \fIs1\fR, returning successive tokens until no tokens remain. The separator
364 string \fIs2\fR can be different from call to call. When no token remains in
365 \fIs1\fR, a null pointer is returned.
367 See Example 3 in the \fBEXAMPLES\fR section for an example of \fBstrtok_r()\fR
368 usage and the explanation in \fBNOTES\fR.
369 .SH EXAMPLES
371 \fBExample 1 \fRSearch for word separators.
373 The following example searches for tokens separated by space characters.
376 .in +2
378 #include <string.h>
379 \&...
380 char *token;
381 char line[] = "LINE TO BE SEPARATED";
382 char *search = " ";
384 /* Token will point to "LINE". */
385 token = strtok(line, search);
387 /* Token will point to "TO". */
388 token = strtok(NULL, search);
390 .in -2
393 \fBExample 2 \fRBreak a Line.
395 The following example uses strtok to break a line into two character strings
396 separated by any combination of SPACEs, TABs, or NEWLINEs.
399 .in +2
401 #include <string.h>
402 \&...
403 struct element {
404        char *key;
405        char *data;
407 \&...
408 char line[LINE_MAX];
409 char *key, *data;
410 \&...
411 key = strtok(line, " \en");
412 data = strtok(NULL, " \en");
414 .in -2
417 \fBExample 3 \fRSearch for tokens.
419 The following example uses both \fBstrtok()\fR and \fBstrtok_r()\fR to search
420 for tokens separated by one or more characters from the string pointed to by
421 the second argument, "/".
424 .in +2
426 #define __EXTENSIONS__
427 #include <stdio.h>
428 #include <string.h>
431 main() {
432         char *buf="5/90/45";
433         char *token;
434         char *lasts;
436         printf("tokenizing \e"%s\e" with strtok():\en", buf);
437         if ((token = strtok(buf, "/")) != NULL) {
438                 printf("token = "%s\e"\en", token);
439                 while ((token = strtok(NULL, "/")) != NULL) {
440                         printf("token = \e"%s\e"\en", token);
441                 }
442         }
444         buf = "//5//90//45//";
445         printf("\entokenizing \e"%s\e" with strtok_r():\en", buf);
446         if ((token = strtok_r(buf, "/", &lasts)) != NULL) {
447                 printf("token = \e"%s\e"\en", token);
448                 while ((token = strtok_r(NULL, "/", &lasts)) != NULL) {
449                         printf("token = \e"%s\e"\en", token);
450                 }
451         }
454 .in -2
457 When compiled and run, this example produces the following output:
460 .in +2
462 tokenizing "5/90/45" with \fBstrtok()\fR:
463 token = "5"
464 token = "90"
465 token = "45"
467 tokenizing "//5//90//45//" with \fBstrtok_r()\fR:
468 token = "5"
469 token = "90"
470 token = "45"
472 .in -2
474 .SH ATTRIBUTES
476 See \fBattributes\fR(5) for descriptions of the following attributes:
478 box;
479 c | c
480 l | l .
481 ATTRIBUTE TYPE  ATTRIBUTE VALUE
483 Interface Stability     See below.
485 MT-Level        See below.
487 Standard        See below.
492 \fBstrlcat()\fR, \fBstrlcpy()\fR, and \fBstrsep()\fR functions are Committed.
493 All the rest are Standard.
495 The \fBstrtok()\fR and \fBstrdup()\fR functions are MT-Safe. The remaining
496 functions are Async-Signal-Safe.
498 For all except \fBstrlcat()\fR, \fBstrlcpy()\fR, and \fBstrsep()\fR, see
499 \fBstandards\fR(5).
500 .SH SEE ALSO
502 \fBmalloc\fR(3C),
503 \fBnewlocale(3C), \fBsetlocale\fR(3C), \fBstrxfrm\fR(3C), \fBuselocale\fR(3C),
504 \fBattributes\fR(5), \fBstandards\fR(5)
505 .SH NOTES
507 When compiling multithreaded applications, the \fB_REENTRANT\fR flag must be
508 defined on the compile line. This flag should only be used in multithreaded
509 applications.
511 A single-threaded application can gain access to \fBstrtok_r()\fR only by
512 defining \fB__EXTENSIONS__\fR or by defining \fB_POSIX_C_SOURCE\fR to a value
513 greater than or equal to 199506L.
515 Except where noted otherwise, all of these functions assume the default
516 locale ``C.'' For some locales,
517 \fBstrxfrm\fR(3C) should be applied to the strings before they are passed to
518 the functions.
520 The \fBstrtok()\fR function is safe to use in multithreaded applications
521 because it saves its internal state in a thread-specific data area.  However,
522 its use is discouraged, even for single-threaded applications. The
523 \fBstrtok_r()\fR function should be used instead.
525 Do not pass the address of a character string literal as the argument \fIs1\fR
526 to either \fBstrtok()\fR or \fBstrtok_r()\fR. Similarly, do not pass a pointer
527 to the address of a character string literal as the argument \fIstringp\fR to
528 \fBstrsep()\fR. These functions can modify the storage pointed to by \fIs1\fR
529 in the case of \fBstrtok()\fR and \fBstrtok_r()\fR or *\fIstringp\fR in the
530 case of \fBstrsep()\fR. The C99 standard specifies that attempting to modify
531 the storage occupied by a string literal results in undefined behavior. This
532 allows compilers (including \fBgcc\fR and the Sun Studio compilers when the
533 \fB-xstrconst\fR flag is used) to place string literals in read-only memory.
534 Note that in Example 1 above, this problem is avoided because the variable
535 \fIline\fR is declared as a writable array of type \fBchar\fR that is
536 initialized by a string literal rather than a pointer to \fBchar\fR that points
537 to a string literal.