]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - StdLib/Include/string.h
1. Update PXE driver to support PXEv6 boot cross subnet.
[mirror_edk2.git] / StdLib / Include / string.h
... / ...
CommitLineData
1/** @file\r
2 The header <string.h> declares one type and several functions, and defines\r
3 one macro useful for manipulating arrays of character type and other objects\r
4 treated as arrays of character type. Various methods are used for\r
5 determining the lengths of the arrays, but in all cases a char * or void *\r
6 argument points to the initial (lowest addressed) character of the array. If\r
7 an array is accessed beyond the end of an object, the behavior is undefined.\r
8\r
9 Where an argument declared as size_t n specifies the length of the array for\r
10 a function, n can have the value zero on a call to that function. Unless\r
11 explicitly stated otherwise in the description of those functions, pointer\r
12 arguments on such a call must still have valid values.\r
13\r
14 For all functions declared in this header, each character shall be\r
15 interpreted as if it had the type unsigned char (and therefore every possible\r
16 object representation is valid and has a different value).\r
17\r
18 The following macros are defined in this file:<BR>\r
19 @verbatim\r
20 NULL\r
21 bcopy(a,b,c) ( memcpy((void *)b, (const void *)a, (size_t)c))\r
22 bcmp(a,b,c) ( memcmp((void *)a, (void *)b, (size_t)c))\r
23 @endverbatim\r
24\r
25 The following types are defined in this file:<BR>\r
26 @verbatim\r
27 size_t Unsigned integer type of the result of the sizeof operator.\r
28 @endverbatim\r
29\r
30 The following functions are declared in this file:<BR>\r
31 @verbatim\r
32 ################ Copying Functions\r
33 void *memcpy (void * __restrict s1, const void * __restrict s2, size_t n);\r
34 void *memmove (void *s1, const void *s2, size_t n);\r
35 char *strcpy (char * __restrict s1, const char * __restrict s2);\r
36 char *strncpy (char * __restrict s1, const char * __restrict s2, size_t n);\r
37 int strncpyX (char * __restrict s1, const char * __restrict s2, size_t n);\r
38\r
39 ################ Concatenation Functions\r
40 char *strcat (char * __restrict s1, const char * __restrict s2);\r
41 char *strncat (char * __restrict s1, const char * __restrict s2, size_t n);\r
42 int strncatX (char * __restrict s1, const char * __restrict s2, size_t n);\r
43\r
44 ################ Comparison Functions\r
45 int memcmp (const void *s1, const void *s2, size_t n);\r
46 int strcmp (const char *s1, const char *s2);\r
47 int strcoll (const char *s1, const char *s2);\r
48 int strncmp (const char *s1, const char *s2, size_t n);\r
49 size_t strxfrm (char * __restrict s1, const char * __restrict s2, size_t n);\r
50\r
51 ################ Search Functions\r
52 void *memchr (const void *s, int c, size_t n);\r
53 char *strchr (const char *s, int c);\r
54 size_t strcspn (const char *s1, const char *s2);\r
55 char *strpbrk (const char *s1, const char *s2);\r
56 char *strrchr (const char *s, int c);\r
57 size_t strspn (const char *s1 , const char *s2);\r
58 char *strstr (const char *s1 , const char *s2);\r
59 char *strtok (char * __restrict s1, const char * __restrict s2);\r
60\r
61 ################ Miscellaneous Functions\r
62 void *memset (void *s, int c, size_t n);\r
63 char *strerror (int num);\r
64 size_t strlen (const char *);\r
65\r
66 ################ BSD Compatibility Functions\r
67 char *strdup (const char *);\r
68 int strerror_r (int, char *, size_t);\r
69 int strcasecmp (const char *s1, const char *s2);\r
70 void *memccpy (void *, const void *, int, size_t);\r
71 int strncasecmp (const char *s1, const char *s2, size_t n);\r
72 size_t strlcpy (char *destination, const char *source, size_t size);\r
73 size_t strlcat (char *destination, const char *source, size_t size);\r
74 char *strsep (register char **stringp, register const char *delim);\r
75 @endverbatim\r
76\r
77 Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
78 This program and the accompanying materials are licensed and made available under\r
79 the terms and conditions of the BSD License that accompanies this distribution.\r
80 The full text of the license may be found at\r
81 http://opensource.org/licenses/bsd-license.\r
82\r
83 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
84 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
85**/\r
86#ifndef _STRING_H\r
87#define _STRING_H\r
88#include <sys/EfiCdefs.h>\r
89\r
90#ifdef _EFI_SIZE_T_\r
91 typedef _EFI_SIZE_T_ size_t;\r
92 #undef _EFI_SIZE_T_\r
93 #undef _BSD_SIZE_T_\r
94#endif\r
95\r
96__BEGIN_DECLS\r
97\r
98/* ################ Copying Functions ################################# */\r
99\r
100/** The memcpy function copies N characters from the object pointed to by Src\r
101 into the object pointed to by Dest. If copying takes place between objects\r
102 that overlap, the behavior is undefined.\r
103\r
104 @param[out] Dest Pointer to the destination of the copy operation.\r
105 @param[in] Src Pointer to the Source data to be copied.\r
106 @param[in] N Number of characters (bytes) to be copied.\r
107\r
108 @return The memcpy function returns the value of Dest.\r
109**/\r
110void *memcpy(void * __restrict Dest, const void * __restrict Src, size_t N);\r
111\r
112/** The memmove function copies N characters from the object pointed to by Src\r
113 into the object pointed to by Dest. Copying takes place as if the N\r
114 characters from the object pointed to by Src are first copied into a\r
115 temporary array of N characters that does not overlap the objects pointed\r
116 to by Dest and Src, and then the N characters from the temporary array are\r
117 copied into the object pointed to by Dest.\r
118\r
119 @param[out] Dest Pointer to the destination of the copy operation.\r
120 @param[in] Src Pointer to the Source data to be copied.\r
121 @param[in] N Number of characters (bytes) to be copied.\r
122\r
123 @return The memmove function returns the value of Dest.\r
124**/\r
125void *memmove(void *Dest, const void *Src, size_t N);\r
126\r
127/** The strcpy function copies the string pointed to by Src (including the\r
128 terminating null character) into the array pointed to by Dest. If copying\r
129 takes place between objects that overlap, the behavior is undefined.\r
130\r
131 @param[out] Dest Pointer to the destination of the copy operation.\r
132 @param[in] Src Pointer to the Source data to be copied.\r
133\r
134 @return The strcpy function returns the value of Dest.\r
135**/\r
136char *strcpy(char * __restrict Dest, const char * __restrict Src);\r
137\r
138/** The strncpy function copies not more than N characters (characters that\r
139 follow a null character are not copied) from the array pointed to by Src to\r
140 the array pointed to by Dest. If copying takes place between objects that\r
141 overlap, the behavior is undefined.\r
142\r
143 If the array pointed to by Src is a string that is shorter than N\r
144 characters, null characters are appended to the copy in the array pointed\r
145 to by Dest, until N characters in all have been written.\r
146\r
147 @param[out] Dest Pointer to the destination of the copy operation.\r
148 @param[in] Src Pointer to the Source data to be copied.\r
149 @param[in] N Number of characters (bytes) to be copied.\r
150\r
151 @return The strncpy function returns the value of Dest.\r
152**/\r
153char *strncpy(char * __restrict Dest, const char * __restrict Src, size_t N);\r
154\r
155/** The strncpyX function copies not more than N-1 characters (characters that\r
156 follow a null character are not copied) from the array pointed to by Src to\r
157 the array pointed to by Dest. Array Dest is guaranteed to be NULL terminated.\r
158 If copying takes place between objects that overlap,\r
159 the behavior is undefined.\r
160\r
161 strncpyX exists because normal strncpy does not indicate if the copy was\r
162 terminated because of exhausting the buffer or reaching the end of Src.\r
163\r
164 @param[out] Dest Pointer to the destination of the copy operation.\r
165 @param[in] Src Pointer to the Source data to be copied.\r
166 @param[in] N Number of characters (bytes) to be copied.\r
167\r
168 @return The strncpyX function returns 0 if the copy operation was\r
169 terminated because it reached the end of Dest. Otherwise,\r
170 a non-zero value is returned indicating how many characters\r
171 remain in Dest.\r
172**/\r
173int strncpyX(char * __restrict Dest, const char * __restrict Src, size_t N);\r
174\r
175/* ################ Concatenation Functions ########################### */\r
176\r
177/** The strcat function appends a copy of the string pointed to by Src\r
178 (including the terminating null character) to the end of the string pointed\r
179 to by Dest. The initial character of Src overwrites the null character at the\r
180 end of Dest. If copying takes place between objects that overlap, the\r
181 behavior is undefined.\r
182\r
183 @param[out] Dest Pointer to the destination of the concatenation operation.\r
184 @param[in] Src Pointer to the Source data to be concatenated.\r
185\r
186 @return The strcat function returns the value of Dest.\r
187**/\r
188char *strcat(char * __restrict Dest, const char * __restrict Src);\r
189\r
190/** The strncat function appends not more than N characters (a null character\r
191 and characters that follow it are not appended) from the array pointed to\r
192 by Src to the end of the string pointed to by Dest. The initial character of\r
193 Src overwrites the null character at the end of Dest. A terminating null\r
194 character is always appended to the result. If copying takes place\r
195 between objects that overlap, the behavior is undefined.\r
196\r
197 @param[out] Dest Pointer to the destination of the concatenation operation.\r
198 @param[in] Src Pointer to the Source data to be concatenated.\r
199 @param[in] N Max Number of characters (bytes) to be concatenated.\r
200\r
201 @return The strncat function returns the value of Dest.\r
202**/\r
203char *strncat(char * __restrict Dest, const char * __restrict Src, size_t N);\r
204\r
205/** The strncatX function appends not more than N characters (a null character\r
206 and characters that follow it are not appended) from the array pointed to\r
207 by Src to the end of the string pointed to by Dest. The initial character of\r
208 Src overwrites the null character at the end of Dest. The result is always\r
209 terminated with a null character. If copying takes place between objects\r
210 that overlap, the behavior is undefined.\r
211\r
212 strncatX exists because normal strncat does not indicate if the operation\r
213 was terminated because of exhausting N or reaching the end of Src.\r
214\r
215 @param[out] Dest Pointer to the destination of the concatenation operation.\r
216 @param[in] Src Pointer to the Source data to be concatenated.\r
217 @param[in] N Max Number of characters (bytes) to be concatenated.\r
218\r
219 @return The strncatX function returns 0 if the operation was terminated\r
220 because it reached the end of Dest. Otherwise, a non-zero value is\r
221 returned indicating how many characters remain in Dest.\r
222**/\r
223int strncatX(char * __restrict s1, const char * __restrict s2, size_t n);\r
224\r
225/* ################ Comparison Functions ############################## */\r
226\r
227/** The memcmp function compares the first N characters of the object pointed\r
228 to by S1 to the first N characters of the object pointed to by S2.\r
229\r
230 @param[out] S1 Pointer to the first object to be compared.\r
231 @param[in] S2 Pointer to the object to be compared to S1.\r
232 @param[in] N Max Number of characters (bytes) to be compared.\r
233\r
234 @return The memcmp function returns an integer greater than, equal to, or\r
235 less than zero, accordingly as the object pointed to by S1 is\r
236 greater than, equal to, or less than the object pointed to by S2.\r
237**/\r
238int memcmp(const void *S1, const void *S2, size_t N);\r
239\r
240/** The strcmp function compares the string pointed to by S1 to the string\r
241 pointed to by S2.\r
242\r
243 @param[out] S1 Pointer to the first string to be compared.\r
244 @param[in] S2 Pointer to the string to be compared to S1.\r
245\r
246 @return The strcmp function returns an integer greater than, equal to, or\r
247 less than zero, accordingly as the string pointed to by S1 is\r
248 greater than, equal to, or less than the string pointed to by S2.\r
249**/\r
250int strcmp(const char *S1, const char *S2);\r
251\r
252/** The strcoll function compares the string pointed to by S1 to the string\r
253 pointed to by S2, both interpreted as appropriate to the LC_COLLATE\r
254 category of the current locale.\r
255\r
256 @param[out] S1 Pointer to the first string to be compared.\r
257 @param[in] S2 Pointer to the string to be compared to S1.\r
258\r
259 @return The strcoll function returns an integer greater than, equal to,\r
260 or less than zero, accordingly as the string pointed to by S1 is\r
261 greater than, equal to, or less than the string pointed to by S2\r
262 when both are interpreted as appropriate to the current locale.\r
263**/\r
264int strcoll(const char *S1, const char *S2);\r
265\r
266/** The strncmp function compares not more than N characters (characters that\r
267 follow a null character are not compared) from the array pointed to by S1\r
268 to the array pointed to by S2.\r
269\r
270 @param[out] S1 Pointer to the first object to be compared.\r
271 @param[in] S2 Pointer to the object to be compared to S1.\r
272 @param[in] N Max Number of characters (bytes) to be compared.\r
273\r
274 @return The strncmp function returns an integer greater than, equal to,\r
275 or less than zero, accordingly as the possibly null-terminated\r
276 array pointed to by S1 is greater than, equal to, or less than\r
277 the possibly null-terminated array pointed to by S2.\r
278**/\r
279int strncmp(const char *S1, const char *S2, size_t N);\r
280\r
281/** The strxfrm function transforms the string pointed to by Src and places the\r
282 resulting string into the array pointed to by Dest. The transformation is\r
283 such that if the strcmp function is applied to two transformed strings, it\r
284 returns a value greater than, equal to, or less than zero, corresponding to\r
285 the result of the strcoll function applied to the same two original\r
286 strings. No more than N characters are placed into the resulting array\r
287 pointed to by Dest, including the terminating null character. If N is zero,\r
288 Dest is permitted to be a null pointer. If copying takes place between\r
289 objects that overlap, the behavior is undefined.\r
290\r
291 @param[out] Dest Pointer to the object to receive the transformed string.\r
292 @param[in] Src Pointer to the string to be transformed.\r
293 @param[in] N Max Number of characters (bytes) to be transformed.\r
294\r
295 @return The strxfrm function returns the length of the transformed string\r
296 (not including the terminating null character). If the value\r
297 returned is N or more, the contents of the array pointed to by Dest\r
298 are indeterminate.\r
299**/\r
300size_t strxfrm(char * __restrict Dest, const char * __restrict Src, size_t N);\r
301\r
302/* ################ Search Functions ################################## */\r
303\r
304/** The memchr function locates the first occurrence of C (converted to an\r
305 unsigned char) in the initial N characters (each interpreted as\r
306 unsigned char) of the object pointed to by S.\r
307\r
308 @param[in] S Pointer to the object to be searched.\r
309 @param[in] C The character value to search for.\r
310 @param[in] N Max Number of characters (bytes) to be searched.\r
311\r
312 @return The memchr function returns a pointer to the located character,\r
313 or a null pointer if the character does not occur in the object.\r
314**/\r
315void *memchr(const void *S, int C, size_t N);\r
316\r
317/** The strchr function locates the first occurrence of C (converted to a char)\r
318 in the string pointed to by S. The terminating null character is considered\r
319 to be part of the string.\r
320\r
321 @param[in] S Pointer to the object to be searched.\r
322 @param[in] C The character value to search for.\r
323\r
324 @return The strchr function returns a pointer to the located character,\r
325 or a null pointer if the character does not occur in the string.\r
326**/\r
327char *strchr(const char *S, int C);\r
328\r
329/** The strcspn function computes the length of the maximum initial segment of\r
330 the string pointed to by S1 which consists entirely of characters NOT from\r
331 the string pointed to by S2.\r
332\r
333 @param[in] S1 Pointer to the object to be searched.\r
334 @param[in] S2 Pointer to the list of characters to search for.\r
335\r
336 @return The strcspn function returns the length of the segment.\r
337**/\r
338size_t strcspn(const char *S1, const char *S2);\r
339\r
340/** The strpbrk function locates the first occurrence in the string pointed to\r
341 by S1 of any character from the string pointed to by S2.\r
342\r
343 @param[in] S1 Pointer to the object to be searched.\r
344 @param[in] S2 Pointer to the list of characters to search for.\r
345\r
346 @return The strpbrk function returns a pointer to the character, or a\r
347 null pointer if no character from S2 occurs in S1.\r
348**/\r
349char *strpbrk(const char *S1, const char *S2);\r
350\r
351/** The strrchr function locates the last occurrence of C (converted to a char)\r
352 in the string pointed to by S. The terminating null character is considered\r
353 to be part of the string.\r
354\r
355 @param[in] S Pointer to the object to be searched.\r
356 @param[in] C The character value to search for.\r
357\r
358 @return The strrchr function returns a pointer to the character, or a\r
359 null pointer if C does not occur in the string.\r
360**/\r
361char *strrchr(const char *S, int C);\r
362\r
363/** The strspn function computes the length of the maximum initial segment of\r
364 the string pointed to by S1 which consists entirely of characters from the\r
365 string pointed to by S2.\r
366\r
367 @param[in] S1 Pointer to the object to be searched.\r
368 @param[in] S2 Pointer to the list of characters to search for.\r
369\r
370 @return The strspn function returns the length of the segment.\r
371**/\r
372size_t strspn(const char *S1 , const char *S2);\r
373\r
374/** The strstr function locates the first occurrence in the string pointed to\r
375 by S1 of the sequence of characters (excluding the terminating null\r
376 character) in the string pointed to by S2.\r
377\r
378 @param[in] S1 Pointer to the object to be searched.\r
379 @param[in] S2 Pointer to the sequence of characters to search for.\r
380\r
381 @return The strstr function returns a pointer to the located string, or a\r
382 null pointer if the string is not found. If S2 points to a string\r
383 with zero length, the function returns S1.\r
384**/\r
385char *strstr(const char *S1 , const char *S2);\r
386\r
387/** Break a string into a sequence of tokens.\r
388\r
389 A sequence of calls to the strtok function breaks the string pointed to by\r
390 S1 into a sequence of tokens, each of which is delimited by a character\r
391 from the string pointed to by S2. The first call in the sequence has a\r
392 non-null first argument; subsequent calls in the sequence have a null first\r
393 argument. The separator string pointed to by S2 may be different from call\r
394 to call.\r
395\r
396 The first call in the sequence searches the string pointed to by S1 for the\r
397 first character that is not contained in the current separator string\r
398 pointed to by S2. If no such character is found, then there are no tokens\r
399 in the string pointed to by S1 and the strtok function returns a null\r
400 pointer. If such a character is found, it is the start of the first token.\r
401\r
402 The strtok function then searches from there for a character that is\r
403 contained in the current separator string. If no such character is found,\r
404 the current token extends to the end of the string pointed to by S1, and\r
405 subsequent searches for a token will return a null pointer. If such a\r
406 character is found, it is overwritten by a null character, which terminates\r
407 the current token. The strtok function saves a pointer to the following\r
408 character, from which the next search for a token will start.\r
409\r
410 Each subsequent call, with a null pointer as the value of the first\r
411 argument, starts searching from the saved pointer and behaves as\r
412 described above.\r
413\r
414 @param[in] S1 Pointer to the string to be tokenized.\r
415 @param[in] S2 Pointer to a list of separator characters.\r
416\r
417 @return The strtok function returns a pointer to the first character of a\r
418 token, or a null pointer if there is no token.\r
419**/\r
420char *strtok(char * __restrict S1, const char * __restrict S2);\r
421\r
422/* ################ Miscellaneous Functions ########################### */\r
423\r
424/** The memset function copies the value of C (converted to an unsigned char)\r
425 into each of the first N characters of the object pointed to by S.\r
426\r
427 @param[out] S Pointer to the first element of the object to be set.\r
428 @param[in] C Value to store in each element of S.\r
429 @param[in] N Number of elements in S to be set.\r
430\r
431 @return The memset function returns the value of S.\r
432**/\r
433void *memset(void *S, int C, size_t N);\r
434\r
435/** The strerror function maps the number in Num to a message string.\r
436 Typically, the values for Num come from errno, but strerror shall map\r
437 any value of type int to a message.\r
438\r
439 @param[in] Num A value to be converted to a message.\r
440\r
441 @return The strerror function returns a pointer to the string, the\r
442 contents of which are locale specific. The array pointed to\r
443 must not be modified by the program, but may be overwritten by\r
444 a subsequent call to the strerror function.\r
445**/\r
446char *strerror(int Num);\r
447\r
448/** The strlen function computes the length of the string pointed to by S.\r
449\r
450 @param[in] S Pointer to the string to determine the length of.\r
451\r
452 @return The strlen function returns the number of characters that\r
453 precede the terminating null character.\r
454**/\r
455size_t strlen(const char *S);\r
456\r
457\r
458/* ################ BSD Compatibility Functions ####################### */\r
459\r
460char *strdup (const char *);\r
461int strerror_r(int, char *, size_t);\r
462int strcasecmp(const char *s1, const char *s2);\r
463void *memccpy (void *, const void *, int, size_t);\r
464int strncasecmp(const char *s1, const char *s2, size_t n);\r
465size_t strlcpy(char *destination, const char *source, size_t size);\r
466size_t strlcat(char *destination, const char *source, size_t size);\r
467\r
468// bcopy is is a void function with the src/dest arguments reversed, being used in socket lib\r
469#define bcopy(a,b,c) ( memcpy((void *)b, (const void *)a, (size_t)c))\r
470\r
471// bcmp is same as memcmp, returns 0 for successful compare, non-zero otherwise\r
472#define bcmp(a,b,c) ( memcmp((void *)a, (void *)b, (size_t)c))\r
473\r
474/*\r
475 * Get next token from string *stringp, where tokens are possibly-empty\r
476 * strings separated by characters from delim.\r
477 *\r
478 * Writes NULs into the string at *stringp to end tokens.\r
479 * delim need not remain constant from call to call.\r
480 * On return, *stringp points past the last NUL written (if there might\r
481 * be further tokens), or is NULL (if there are definitely no more tokens).\r
482 *\r
483 * If *stringp is NULL, strsep returns NULL.\r
484 */\r
485char *\r
486strsep(\r
487 register char **stringp,\r
488 register const char *delim\r
489 );\r
490\r
491__END_DECLS\r
492\r
493#endif /* _STRING_H */\r