string.h revision 2aa62f2bc9a9654687b377d9ca8a8c2c860a3852
12aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm/** @file 22aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm The header <string.h> declares one type and several functions, and defines 32aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm one macro useful for manipulating arrays of character type and other objects 42aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm treated as arrays of character type. Various methods are used for 52aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm determining the lengths of the arrays, but in all cases a char * or void * 62aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm argument points to the initial (lowest addressed) character of the array. If 72aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm an array is accessed beyond the end of an object, the behavior is undefined. 82aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 92aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm Where an argument declared as size_t n specifies the length of the array for 102aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm a function, n can have the value zero on a call to that function. Unless 112aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm explicitly stated otherwise in the description of those functions, pointer 122aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm arguments on such a call shall still have valid values. 132aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 142aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm For all functions declared in this header, each character shall be 152aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm interpreted as if it had the type unsigned char (and therefore every possible 162aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm object representation is valid and has a different value). 172aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 182aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmCopyright (c) 2010, Intel Corporation. All rights reserved.<BR> 192aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmThis program and the accompanying materials are licensed and made available under 202aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmthe terms and conditions of the BSD License that accompanies this distribution. 212aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmThe full text of the license may be found at 222aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmhttp://opensource.org/licenses/bsd-license.php. 232aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 242aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmTHE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 252aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmWITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 262aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 272aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm**/ 282aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm#ifndef _STRING_H 292aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm#define _STRING_H 302aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm#include <sys/EfiCdefs.h> 312aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 322aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm#ifdef _EFI_SIZE_T_ 332aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm typedef _EFI_SIZE_T_ size_t; 342aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm #undef _EFI_SIZE_T_ 352aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm #undef _BSD_SIZE_T_ 362aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm#endif 372aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 382aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm__BEGIN_DECLS 392aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 402aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm/* ################ Copying Functions ################################# */ 412aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 422aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm/** The memcpy function copies n characters from the object pointed to by s2 432aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm into the object pointed to by s1. If copying takes place between objects 442aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm that overlap, the behavior is undefined. 452aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 462aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm @return The memcpy function returns the value of s1. 472aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm**/ 482aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmvoid *memcpy(void * __restrict s1, const void * __restrict s2, size_t n); 492aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 502aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm/** The memmove function copies n characters from the object pointed to by s2 512aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm into the object pointed to by s1. Copying takes place as if the n 522aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm characters from the object pointed to by s2 are first copied into a 532aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm temporary array of n characters that does not overlap the objects pointed 542aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm to by s1 and s2, and then the n characters from the temporary array are 552aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm copied into the object pointed to by s1. 562aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 572aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm @return The memmove function returns the value of s1. 582aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm**/ 592aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmvoid *memmove(void *s1, const void *s2, size_t n); 602aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 612aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm/** The strcpy function copies the string pointed to by s2 (including the 622aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm terminating null character) into the array pointed to by s1. If copying 632aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm takes place between objects that overlap, the behavior is undefined. 642aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 652aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm @return The strcpy function returns the value of s1. 662aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm**/ 672aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmchar *strcpy(char * __restrict s1, const char * __restrict s2); 682aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 692aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm/** The strncpy function copies not more than n characters (characters that 702aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm follow a null character are not copied) from the array pointed to by s2 to 712aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm the array pointed to by s1. If copying takes place between objects that 722aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm overlap, the behavior is undefined. 732aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 742aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm If the array pointed to by s2 is a string that is shorter than n 752aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm characters, null characters are appended to the copy in the array pointed 762aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm to by s1, until n characters in all have been written. 772aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 782aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm @return The strncpy function returns the value of s1. 792aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm**/ 802aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmchar *strncpy(char * __restrict s1, const char * __restrict s2, size_t n); 812aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 822aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm/** The strncpyX function copies not more than n-1 characters (characters that 832aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm follow a null character are not copied) from the array pointed to by s2 to 842aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm the array pointed to by s1. Array s1 is guaranteed to be NULL terminated. 852aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm If copying takes place between objects that overlap, 862aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm the behavior is undefined. 872aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 882aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm strncpyX exists because normal strncpy does not indicate if the copy was 892aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm terminated because of exhausting the buffer or reaching the end of s2. 902aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 912aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm @return The strncpyX function returns 0 if the copy operation was 922aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm terminated because it reached the end of s1. Otherwise, 932aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm a non-zero value is returned indicating how many characters 942aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm remain in s1. 952aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm**/ 962aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmint strncpyX(char * __restrict s1, const char * __restrict s2, size_t n); 972aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 982aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm/* ################ Concatenation Functions ########################### */ 992aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 1002aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm/** The strcat function appends a copy of the string pointed to by s2 1012aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm (including the terminating null character) to the end of the string pointed 1022aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm to by s1. The initial character of s2 overwrites the null character at the 1032aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm end of s1. If copying takes place between objects that overlap, the 1042aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm behavior is undefined. 1052aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 1062aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm @return The strcat function returns the value of s1. 1072aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm**/ 1082aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmchar *strcat(char * __restrict s1, const char * __restrict s2); 1092aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 1102aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm/** The strncat function appends not more than n characters (a null character 1112aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm and characters that follow it are not appended) from the array pointed to 1122aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm by s2 to the end of the string pointed to by s1. The initial character of 1132aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm s2 overwrites the null character at the end of s1. A terminating null 1142aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm character is always appended to the result. If copying takes place 1152aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm between objects that overlap, the behavior is undefined. 1162aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 1172aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm @return The strncat function returns the value of s1. 1182aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm**/ 1192aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmchar *strncat(char * __restrict s1, const char * __restrict s2, size_t n); 1202aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 1212aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm/** The strncatX function appends not more than n characters (a null character 1222aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm and characters that follow it are not appended) from the array pointed to 1232aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm by s2 to the end of the string pointed to by s1. The initial character of 1242aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm s2 overwrites the null character at the end of s1. The result is always 1252aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm terminated with a null character. If copying takes place between objects 1262aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm that overlap, the behavior is undefined. 1272aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 1282aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm strncatX exists because normal strncat does not indicate if the operation 1292aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm was terminated because of exhausting n or reaching the end of s2. 1302aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 1312aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm @return The strncatX function returns 0 if the operation was terminated 1322aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm because it reached the end of s1. Otherwise, a non-zero value is 1332aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm returned indicating how many characters remain in s1. 1342aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm**/ 1352aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmint strncatX(char * __restrict s1, const char * __restrict s2, size_t n); 1362aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 1372aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm/* ################ Comparison Functions ############################## */ 1382aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 1392aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm/** The memcmp function compares the first n characters of the object pointed 1402aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm to by s1 to the first n characters of the object pointed to by s2. 1412aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 1422aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm @return The memcmp function returns an integer greater than, equal to, or 1432aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm less than zero, accordingly as the object pointed to by s1 is 1442aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm greater than, equal to, or less than the object pointed to by s2. 1452aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm**/ 1462aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmint memcmp(const void *s1, const void *s2, size_t n); 1472aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 1482aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm/** The strcmp function compares the string pointed to by s1 to the string 1492aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm pointed to by s2. 1502aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 1512aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm @return The strcmp function returns an integer greater than, equal to, or 1522aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm less than zero, accordingly as the string pointed to by s1 is 1532aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm greater than, equal to, or less than the string pointed to by s2. 1542aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm**/ 1552aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmint strcmp(const char *s1, const char *s2); 1562aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 1572aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm/** The strcoll function compares the string pointed to by s1 to the string 1582aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm pointed to by s2, both interpreted as appropriate to the LC_COLLATE 1592aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm category of the current locale. 1602aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 1612aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm @return The strcoll function returns an integer greater than, equal to, 1622aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm or less than zero, accordingly as the string pointed to by s1 is 1632aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm greater than, equal to, or less than the string pointed to by s2 1642aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm when both are interpreted as appropriate to the current locale. 1652aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm**/ 1662aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmint strcoll(const char *s1, const char *s2); 1672aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 1682aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm/** The strncmp function compares not more than n characters (characters that 1692aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm follow a null character are not compared) from the array pointed to by s1 1702aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm to the array pointed to by s2. 1712aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 1722aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm @return The strncmp function returns an integer greater than, equal to, 1732aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm or less than zero, accordingly as the possibly null-terminated 1742aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm array pointed to by s1 is greater than, equal to, or less than 1752aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm the possibly null-terminated array pointed to by s2. 1762aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm**/ 1772aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmint strncmp(const char *s1, const char *s2, size_t n); 1782aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 1792aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm/** The strxfrm function transforms the string pointed to by s2 and places the 1802aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm resulting string into the array pointed to by s1. The transformation is 1812aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm such that if the strcmp function is applied to two transformed strings, it 1822aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm returns a value greater than, equal to, or less than zero, corresponding to 1832aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm the result of the strcoll function applied to the same two original 1842aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm strings. No more than n characters are placed into the resulting array 1852aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm pointed to by s1, including the terminating null character. If n is zero, 1862aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm s1 is permitted to be a null pointer. If copying takes place between 1872aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm objects that overlap, the behavior is undefined. 1882aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 1892aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm @return The strxfrm function returns the length of the transformed string 1902aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm (not including the terminating null character). If the value 1912aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm returned is n or more, the contents of the array pointed to by s1 1922aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm are indeterminate. 1932aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm**/ 1942aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmsize_t strxfrm(char * __restrict s1, const char * __restrict s2, size_t n); 1952aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 1962aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm/* ################ Search Functions ################################## */ 1972aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 1982aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm/** The memchr function locates the first occurrence of c (converted to an 1992aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm unsigned char) in the initial n characters (each interpreted as 2002aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm unsigned char) of the object pointed to by s. 2012aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 2022aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm @return The memchr function returns a pointer to the located character, 2032aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm or a null pointer if the character does not occur in the object. 2042aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm**/ 2052aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmvoid *memchr(const void *s, int c, size_t n); 2062aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 2072aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm/** The strchr function locates the first occurrence of c (converted to a char) 2082aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm in the string pointed to by s. The terminating null character is considered 2092aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm to be part of the string. 2102aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 2112aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm @return The strchr function returns a pointer to the located character, 2122aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm or a null pointer if the character does not occur in the string. 2132aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm**/ 2142aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmchar *strchr(const char *s, int c); 2152aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 2162aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm/** The strcspn function computes the length of the maximum initial segment of 2172aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm the string pointed to by s1 which consists entirely of characters NOT from 2182aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm the string pointed to by s2. 2192aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 2202aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm @return The strcspn function returns the length of the segment. 2212aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm**/ 2222aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmsize_t strcspn(const char *s1, const char *s2); 2232aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 2242aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm/** The strpbrk function locates the first occurrence in the string pointed to 2252aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm by s1 of any character from the string pointed to by s2. 2262aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 2272aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm @return The strpbrk function returns a pointer to the character, or a 2282aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm null pointer if no character from s2 occurs in s1. 2292aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm**/ 2302aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmchar *strpbrk(const char *s1, const char *s2); 2312aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 2322aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm/** The strrchr function locates the last occurrence of c (converted to a char) 2332aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm in the string pointed to by s. The terminating null character is considered 2342aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm to be part of the string. 2352aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 2362aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm @return The strrchr function returns a pointer to the character, or a 2372aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm null pointer if c does not occur in the string. 2382aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm**/ 2392aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmchar *strrchr(const char *s, int c); 2402aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 2412aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm/** The strspn function computes the length of the maximum initial segment of 2422aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm the string pointed to by s1 which consists entirely of characters from the 2432aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm string pointed to by s2. 2442aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 2452aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm @return The strspn function returns the length of the segment. 2462aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm**/ 2472aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmsize_t strspn(const char *s1 , const char *s2); 2482aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 2492aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm/** The strstr function locates the first occurrence in the string pointed to 2502aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm by s1 of the sequence of characters (excluding the terminating null 2512aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm character) in the string pointed to by s2. 2522aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 2532aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm @return The strstr function returns a pointer to the located string, or a 2542aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm null pointer if the string is not found. If s2 points to a string 2552aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm with zero length, the function returns s1. 2562aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm**/ 2572aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmchar *strstr(const char *s1 , const char *s2); 2582aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 2592aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm/** A sequence of calls to the strtok function breaks the string pointed to by 2602aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm s1 into a sequence of tokens, each of which is delimited by a character 2612aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm from the string pointed to by s2. The first call in the sequence has a 2622aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm non-null first argument; subsequent calls in the sequence have a null first 2632aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm argument. The separator string pointed to by s2 may be different from call 2642aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm to call. 2652aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 2662aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm The first call in the sequence searches the string pointed to by s1 for the 2672aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm first character that is not contained in the current separator string 2682aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm pointed to by s2. If no such character is found, then there are no tokens 2692aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm in the string pointed to by s1 and the strtok function returns a null 2702aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm pointer. If such a character is found, it is the start of the first token. 2712aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 2722aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm The strtok function then searches from there for a character that is 2732aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm contained in the current separator string. If no such character is found, 2742aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm the current token extends to the end of the string pointed to by s1, and 2752aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm subsequent searches for a token will return a null pointer. If such a 2762aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm character is found, it is overwritten by a null character, which terminates 2772aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm the current token. The strtok function saves a pointer to the following 2782aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm character, from which the next search for a token will start. 2792aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 2802aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm Each subsequent call, with a null pointer as the value of the first 2812aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm argument, starts searching from the saved pointer and behaves as 2822aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm described above. 2832aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 2842aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm @return The strtok function returns a pointer to the first character of a 2852aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm token, or a null pointer if there is no token. 2862aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm**/ 2872aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmchar *strtok(char * __restrict s1, const char * __restrict s2); 2882aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 2892aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm/* ################ Miscellaneous Functions ########################### */ 2902aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 2912aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm/** The memset function copies the value of c (converted to an unsigned char) 2922aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm into each of the first n characters of the object pointed to by s. 2932aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 2942aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm @return The memset function returns the value of s. 2952aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm**/ 2962aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmvoid *memset(void *s, int c, size_t n); 2972aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 2982aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm/** The strerror function maps the number in errnum to a message string. 2992aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm Typically, the values for errnum come from errno, but strerror shall map 3002aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm any value of type int to a message. 3012aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 3022aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm The implementation shall behave as if no library function calls the 3032aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm strerror function. 3042aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 3052aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm @return The strerror function returns a pointer to the string, the 3062aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm contents of which are locale specific. The array pointed to 3072aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm shall not be modified by the program, but may be overwritten by 3082aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm a subsequent call to the strerror function. 3092aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm**/ 3102aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmchar *strerror(int num); 3112aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 3122aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm/** The strlen function computes the length of the string pointed to by s. 3132aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 3142aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm @return The strlen function returns the number of characters that 3152aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm precede the terminating null character. 3162aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm**/ 3172aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmsize_t strlen(const char *); 3182aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 3192aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 3202aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm/* ################ BSD Compatibility Functions ####################### */ 3212aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 3222aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmchar *strdup (const char *); 3232aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmint strerror_r(int, char *, size_t); 3242aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmint strcasecmp(const char *s1, const char *s2); 3252aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylmvoid *memccpy (void *, const void *, int, size_t); 3262aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 3272aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm__END_DECLS 3282aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm 3292aa62f2bc9a9654687b377d9ca8a8c2c860a3852darylm#endif /* _STRING_H */ 330