6001 strcat(9f) needs a manpage
[unleashed.git] / usr / src / man / man9f / string.9f
blob49d6e957c7ee9fd397e03f7397a4be4e7cfcf77e
1 '\" te
2 .\" Copyright (c) 2009, Sun Microsystems, Inc.  All Rights Reserved.
3 .\" 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.
4 .\" 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.
5 .\" 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]
6 .TH STRING 9F "Mar 14, 2016"
7 .SH NAME
8 string, strcasecmp, strncasecmp, strcat, strncat, strlcat, strchr,
9 strrchr, strcmp, strncmp, strcpy, strncpy, strlcpy, strfree, strspn,
10 strdup, ddi_strdup, strlen, strnlen \- string operations
11 .SH SYNOPSIS
12 .LP
13 .nf
14 #include <sys/ddi.h>
15 #include <sys/sunddi.h>
17 \fBint\fR \fBstrcasecmp\fR(\fBconst char *\fR\fIs1\fR, \fBconst char *\fR\fIs2\fR);
18 .fi
20 .LP
21 .nf
22 \fBint\fR \fBstrncasecmp\fR(\fBconst char *\fR\fIs1\fR, \fBconst char *\fR\fIs2\fR, \fBsize_t\fR \fIn\fR);
23 .fi
25 .LP
26 .nf
27 \fBchar *\fR\fBstrcat\fR(\fBchar *\fR \fIs1\fR, \fBconst char *\fR \fIs2\fR);
28 .fi
30 .LP
31 .nf
32 \fBchar *\fR\fBstrncat\fR(\fBchar *\fR \fIs1\fR, \fBconst char *\fR \fIs2\fR, \fBsize_t\fR \fIn\fR);
33 .fi
35 .LP
36 .nf
37 \fBsize_t\fR \fBstrlcat\fR(\fBchar *\fR\fIdst\fR, \fBconst char *\fR\fIsrc\fR, \fBsize_t\fR \fIdstsize\fR);
38 .fi
40 .LP
41 .nf
42 \fBchar *\fR\fBstrchr\fR(\fBconst char *\fR\fIstr\fR, \fBint\fR \fIchr\fR);
43 .fi
45 .LP
46 .nf
47 \fBchar *\fR\fBstrrchr\fR(\fBconst char *\fR\fIstr\fR, \fBint\fR \fIchr\fR);
48 .fi
50 .LP
51 .nf
52 \fBint\fR \fBstrcmp\fR(\fBconst char *\fR\fIs1\fR, \fBconst char *\fR\fIs2\fR);
53 .fi
55 .LP
56 .nf
57 \fBint\fR \fBstrncmp\fR(\fBconst char *\fR\fIs1\fR, \fBconst char *\fR\fIs2\fR, \fBsize_t\fR \fIn\fR);
58 .fi
60 .LP
61 .nf
62 \fBchar *\fR\fBstrcpy\fR(\fBchar *\fR \fIdst\fR, \fBconst char *\fR \fIsrc\fR);
63 .fi
65 .LP
66 .nf
67 \fBchar *\fR\fBstrncpy\fR(\fBchar *\fR \fIdst\fR, \fBconst char *\fR \fIsrc\fR, \fBsize_t\fR \fIn\fR);
68 .fi
70 .LP
71 .nf
72 \fBsize_t\fR \fBstrlcpy\fR(\fBchar *\fR\fIdst\fR, \fBconst char *\fR\fIsrc\fR, \fBsize_t\fR \fIdstsize\fR);
73 .fi
75 .LP
76 .nf
77 \fBvoid\fR \fBstrfree\fR(\fBchar *\fR\fIs\fR);
78 .fi
80 .LP
81 .nf
82 \fBsize_t\fR \fBstrspn\fR(\fBconst char *\fR\fIs1\fR, \fBconst char *\fR\fIs2\fR);
83 .fi
85 .LP
86 .nf
87 \fBchar *\fR\fBstrdup\fR(\fBconst char *\fR\fIs1\fR);
88 .fi
90 .LP
91 .nf
92 \fBchar *\fR\fBddi_strdup\fR(\fBconst char *\fR\fIs1\fR, \fBint\fR \fIflag\fR);
93 .fi
95 .LP
96 .nf
97 \fBsize_t\fR \fBstrlen\fR(\fBconst char *\fR\fIs\fR);
98 .fi
102 \fBsize_t\fR \fBstrnlen\fR(\fBconst char *\fR\fIs\fR, \fBsize_t\fR \fIn\fR);
105 .SH INTERFACE LEVEL
107 Solaris DDI specific (Solaris DDI).
108 .SH DESCRIPTION
110 The arguments \fIs\fR, \fIs1\fR, and \fIs2\fR point to strings (arrays of
111 characters terminated by a null character). The \fBstrcat()\fR,
112 \fBstrncat()\fR, \fBstrlcat()\fR, \fBstrcpy()\fR, \fBstrncpy()\fR,
113 \fBstrlcpy()\fR, and \fBstrfree()\fR functions all alter their first argument.
114 Additionally, the \fBstrcpy()\fR function does not check for overflow of the
115 array.
116 .SS "\fBstrcasecmp()\fR, \fBstrncasecmp()\fR"
118 The \fBstrcasecmp()\fR and \fBstrncasecmp()\fR functions are case-insensitive
119 versions of  \fBstrcmp()\fR and \fBstrncmp()\fR respectively, described below.
120 They assume the \fBASCII\fR character set and ignore differences in case when
121 comparing lower and upper case characters.
122 .SS "\fBstrcat()\fR, \fBstrncat()\fR, and \fBstrlcat()\fR"
124 The \fBstrcat()\fR function appends a copy of string \fIs2\fR, including the
125 terminating null character, to the end of string \fIs1\fR. The \fBstrncat()\fR
126 function appends at most \fIn\fR characters of \fIs2\fR to \fIs1\fR, not
127 including any terminating null character, and then appends a null character.
128 Each returns a pointer to the null-terminated result. The initial character of
129 \fIs2\fR overrides the null character at the end of \fIs1\fR. If copying takes
130 place between objects that overlap, the behavior of \fBstrcat()\fR,
131 \fBstrncat()\fR, and \fBstrlcat()\fR is undefined.
134 The \fBstrlcat()\fR function appends  at most
135 (\fIdstsize\fR-\fBstrlen\fR(\fIdst\fR)-1) characters of \fIsrc\fR to \fIdst\fR
136 (\fIdstsize\fR being the  size of the  string buffer \fIdst\fR). If the string
137 pointed to by \fIdst\fR contains a null-terminated string that fits into
138 \fIdstsize\fR bytes when \fBstrlcat()\fR is called, the string pointed to by
139 \fIdst\fR will be a null-terminated string that fits in \fIdstsize\fR bytes
140 (including the terminating null character) when it completes, and the initial
141 character of \fIsrc\fR will override the null character at  the end of
142 \fIdst\fR. If the string pointed to by \fIdst\fR is longer than \fIdstsize\fR
143 bytes when \fBstrlcat()\fR is called, the string pointed to by \fIdst\fR will
144 not be changed. The function returns
145 \fBmin\fR{\fIdstsize\fR,\fBstrlen\fR(\fIdst\fR)}+\fBstrlen\fR(\fIsrc\fR).
146 Buffer overflow can be checked as  follows:
148 .in +2
150 if (strlcat(dst, src, dstsize) >= dstsize)
151         return \(mi1;
153 .in -2
155 .SS "\fBstrchr()\fR, \fBstrrchr()\fR"
157 The \fBstrchr()\fR function returns a pointer to the first occurrence of
158 \fIc\fR (converted to a  \fBchar\fR) in string \fIs\fR, or a null pointer if
159 \fIc\fR does not occur in the string. The \fBstrrchr()\fR function returns a
160 pointer to the last occurrence of \fIc\fR. The null character terminating a
161 string is considered to be part of the string.
162 .SS "\fBstrcmp()\fR, \fBstrncmp()\fR"
164 The \fBstrcmp()\fR function compares two strings byte-by-byte, according to the
165 ordering of your machine's character set.  The function returns an integer
166 greater than, equal to, or less than 0, if  the string pointed to by \fIs1\fR
167 is greater than, equal to, or less than the string pointed to by \fIs2\fR
168 respectively. The sign of a non-zero return value is determined  by the sign of
169 the difference between the values of the first pair of bytes that differ in the
170 strings being compared. The \fBstrncmp()\fR function makes the same comparison
171 but looks at a maximum of \fIn\fR bytes. Bytes following a null byte are not
172 compared.
173 .SS "\fBstrcpy()\fR, \fBstrncpy()\fR, \fBstrlcpy()\fR"
175 The \fBstrcpy()\fR function copies string \fIs2\fR to \fIs1\fR, including the
176 terminating null character, stopping after the null character has been copied.
177 The \fBstrncpy()\fR function copies exactly \fIn\fR bytes, truncating \fIs2\fR
178 or adding null characters to \fIs1\fR if necessary. The result will not be
179 null-terminated if the length of \fIs2\fR is \fIn\fR or more. Both the
180 \fBstrcpy()\fR and \fBstrncpy()\fR functions return \fIs1\fR. If copying takes
181 place between objects that overlap, the behavior of \fBstrcpy()\fR,
182 \fBstrncpy()\fR, and \fBstrlcpy()\fR is undefined.
185 The \fBstrlcpy()\fR function copies  at most \fIdstsize\fR\(mi1 characters
186 (\fIdstsize\fR being the  size of the  string buffer \fIdst\fR) from \fIsrc\fR
187 to \fIdst\fR,  truncating \fIsrc\fR if necessary.  The  result is always
188 null-terminated. The function returns \fBstrlen\fR(\fIsrc\fR). Buffer overflow
189 can be checked as  follows:
191 .in +2
193 if (strlcpy(dst, src, dstsize) >= dstsize)
194         return \(mi1;
196 .in -2
198 .SS "\fBstrfree()\fR"
200 The \fBstrfree()\fR function frees the memory associated with the string
201 pointed to by \fIs\fR.  This memory pointed to by \fIs\fR must be of size
202 \fBstrlen\fR(\fIs\fR)+1, and must have been allocated (either directly or
203 indirectly) by \fBkmem_alloc\fR(9F) or \fBkmem_zalloc\fR(9F).
204 .SS "\fBstrspn()\fR"
206 The \fBstrspn()\fR function returns the length of the initial segment of string
207 \fIs1\fR that consists entirely of characters from string \fIs2\fR.
208 .SS "\fBstrdup()\fR, \fBddi_strdup()\fR"
210 The \fBddi_strdup()\fR function returns a pointer to a new string that is a
211 duplicate of the string pointed to by \fIs1\fR. The returned pointer can be
212 passed to \fBstrfree()\fR or \fBkmem_free\fR(9F). The space for the new string
213 is obtained using \fBkmem_alloc()\fR. flag can be either \fBKM_SLEEP\fR or
214 \fBKM_NOSLEEP\fR, and determines whether the caller can sleep for memory.
215 \fBKM_SLEEP\fR allocations may sleep but are guaranteed to succeed.
216 \fBKM_NOSLEEP\fR allocations are guaranteed not to sleep but may fail (return
217 \fINULL\fR) if no memory is currently available.
220 The \fBstrdup()\fR function behaves the same as the \fBddi_strdup()\fR when
221 called with the \fBKM_SLEEP\fR flag. This means that \fBstrdup()\fR can sleep
222 until memory is available and will always succeed.
223 .SS "\fBstrlen()\fR, \fBstrnlen()\fR"
225 The \fBstrlen()\fR function returns the number of bytes in \fIs\fR, not
226 including the terminating null character.
229 The \fBstrnlen()\fR function returns the smaller of \fIn\fR or the number of
230 bytes in \fIs\fR, not including the terminating null character. The
231 \fBstrnlen()\fR function never examines more than \fIn\fR bytes of the string
232 pointed to by \fIs\fR.
233 .SH CONTEXT
235 The \fBstrdup()\fR and \fBddi_strdup()\fR functions can be called from user or
236 kernel context.
239 The \fBddi_strdup()\fR function can be called from interrupt context only if
240 the \fBKM_NOSLEEP\fR flag is set.
243 All the other string manipulation functions can be called from user, interrupt,
244 or kernel context.
245 .SH ATTRIBUTES
247 See \fBattributes\fR(5) for descriptions of the following attributes:
252 box;
253 c | c
254 l | l .
255 ATTRIBUTE TYPE  ATTRIBUTE VALUE
257 Interface Stability     Committed
260 .SH SEE ALSO
262 \fBstring\fR(3C), \fBattributes\fR(5), \fBbcopy\fR(9F), \fBddi_copyin\fR(9F),
263 \fBkmem_alloc\fR(9F)
266 \fIWriting Device Drivers\fR
267 .SH NOTES
269 If copying takes place between objects that overlap, the behavior of
270 \fBstrlcat()\fR, \fBstrncat()\fR, \fBstrcpy()\fR, \fBstrlcpy()\fR, and
271 \fBstrncpy()\fR is undefined.