welibc
A clear, secure, and well documented standard C library
|
Declares types, functions, and macros for manipulating arrays of character type and other objects treated as arrays of character type. More...
Go to the source code of this file.
Macros | |
#define | _NULL |
#define | _SIZE_T |
#define | NULL ((void *) 0) |
Typedefs | |
typedef unsigned long | size_t |
Functions | |
void * | memchr (const void *s, int c, size_t n) |
Searches for a given character. More... | |
int | memcmp (const void *s1, const void *s2, size_t n) |
Compares the first n characters of s1 and s2. More... | |
void * | memcpy (void *s1, const void *s2, size_t n) |
Copies n characters from s2 into s1. More... | |
void * | memmove (void *s1, const void *s2, size_t n) |
Copies n characters from s2 into s1. More... | |
void * | memset (void *s, int c, size_t n) |
Copies the value c into the first n characters of object s. More... | |
char * | strcat (char *s1, const char *s2) |
Concatenates two strings. More... | |
char * | strchr (const char *s, int c) |
Locate the first occurrence of a character in a string. More... | |
int | strcmp (const char *s1, const char *s2) |
Compares the strings pointed to be s1 and s2. More... | |
char * | strcpy (char *s1, const char *s2) |
Copies a string with null terminator from s2 into s1. More... | |
size_t | strcspn (const char *s1, const char *s2) |
Find the length of the span of complementary characters to s2 in s1. More... | |
char * | strerror (int errnum) |
Maps an error number to an error message string. More... | |
size_t | strlen (const char *s) |
Computes the length of a string. More... | |
char * | strncat (char *s1, const char *s2, size_t n) |
Concatenates two strings, appending no more than n characters. More... | |
int | strncmp (const char *s1, const char *s2, size_t n) |
Compares the strings pointed to be s1 and s2. More... | |
char * | strncpy (char *s1, const char *s2, size_t n) |
Copies no more than n characters with null terminator from s2 to s1. More... | |
char * | strpbrk (const char *s1, const char *s2) |
Locate the first occurrence of any of s2 in s1. More... | |
char * | strrchr (const char *s, int c) |
Locate the last occurrence of a character in a string. More... | |
size_t | strspn (const char *s1, const char *s2) |
Find the length of the span of characters in s2 in s1. More... | |
char * | strstr (const char *s1, const char *s2) |
Locate the first occurrence of a string in a another string. More... | |
char * | strtok (char *s1, const char *s2) |
Breaks a string into a sequence of tokens split on a given delimiter. More... | |
Declares types, functions, and macros for manipulating arrays of character type and other objects treated as arrays of character type.
Definition in file string.h.
void* memchr | ( | const void * | s, |
int | c, | ||
size_t | n | ||
) |
Searches for a given character.
*s | Object being searched |
c | Character to find |
n | Maximum number of character to search |
The memchr function locates the first occurrence of c (converted to an unsigned char) in the initial n characters (each interpreted as unsigned char) of the object pointed to by s.
NULL | The character does not occur in the object |
Definition at line 54 of file memchr.c.
References NULL.
int memcmp | ( | const void * | s1, |
const void * | s2, | ||
size_t | n | ||
) |
Compares the first n characters of s1 and s2.
*s1 | The first object to be compared |
*s2 | The second object to be compared |
n | The number of characters to compare |
The memcmp function compares the first n characters of the object pointed to by s1 to the first n characters of the object pointed to by s2.
>0 | s1 is greater than s2 or no comparison could be made |
0 | s1 is equal to s2 |
<0 | s1 is less than s2 |
Definition at line 68 of file memcmp.c.
Referenced by strcmp(), and strncmp().
void* memcpy | ( | void * | s1, |
const void * | s2, | ||
size_t | n | ||
) |
Copies n characters from s2 into s1.
*s1 | The destination location to which to copy characters |
*s2 | The source location from which to copy characters |
n | The number of characters to copy |
The memcpy function copies n characters from the object pointed to by s2 into the object pointed to by s1.
Definition at line 60 of file memcpy.c.
References memmove().
void* memmove | ( | void * | s1, |
const void * | s2, | ||
size_t | n | ||
) |
Copies n characters from s2 into s1.
*s1 | The destination location to which to copy characters |
*s2 | The source location from which to copy characters |
n | The number of characters to copy |
The memmove function copies n characters from the object pointed to by s2 into the object pointed to by s1. Copying takes place as if the n characters from the object pointed to by s2 are first copied into a temporary array of n characters that does not overlap the objects pointed to by s1 and s2, and then the n characters from the temporary array are copied into the object pointed to by s1.
Definition at line 59 of file memmove.c.
Referenced by memcpy(), strcpy(), strncat(), and strncpy().
void* memset | ( | void * | s, |
int | c, | ||
size_t | n | ||
) |
Copies the value c into the first n characters of object s.
*s | Destination object having its memory set |
c | Value being written |
n | Number of characters to be set |
The memset function copies the value c (converted to an unsigned char) into each of the first n characters of the object pointed to by s.
Definition at line 52 of file memset.c.
Referenced by strncpy().
char* strcat | ( | char * | s1, |
const char * | s2 | ||
) |
Concatenates two strings.
*s1 | Destination string |
*s2 | String to be appended |
The strcat function appends a copy of the string pointed to by s2 (including the terminating null character) to the end of the string pointed to by s1. The initial character of s2 overwrites the null character at the end of s1. If copying takes place between objects that overlap, the behavior is undefined.
Definition at line 60 of file strcat.c.
References strcpy(), and strlen().
char* strchr | ( | const char * | s, |
int | c | ||
) |
Locate the first occurrence of a character in a string.
*s | String being searched |
c | Character to find |
The strchr function locates the first occurrence of c (converted to a char) in the string pointed to by s. The terminating null character is considered to be a part of the string.
NULL | The character does not occur in the string |
Definition at line 53 of file strchr.c.
References NULL.
Referenced by strcspn(), strspn(), and strstr().
int strcmp | ( | const char * | s1, |
const char * | s2 | ||
) |
Compares the strings pointed to be s1 and s2.
*s1 | The first string to be compared |
*s2 | The second string to be compared |
The strcmp function compares the string pointed to by s1 to the string pointed to by s2.
>0 | s1 is greater than s2 or no comparison could be made |
0 | s1 is equal to s2 |
<0 | s1 is less than s2 |
Definition at line 54 of file strcmp.c.
References memcmp(), and strlen().
char* strcpy | ( | char * | s1, |
const char * | s2 | ||
) |
Copies a string with null terminator from s2 into s1.
*s1 | The destination array |
*s2 | The source string |
The strcpy function copies the string pointed to by s2 (including the terminating null character) into the array pointed to by s1.
Definition at line 54 of file strcpy.c.
References memmove(), and strlen().
Referenced by strcat(), and strncpy().
size_t strcspn | ( | const char * | s1, |
const char * | s2 | ||
) |
Find the length of the span of complementary characters to s2 in s1.
*s1 | String being searched |
*s2 | String of characters not counted in the span being found |
The strcspn function computes the length of the maximum initial segment of the string pointed to by s1 which consists entirely of characters not from the string pointed to by s2.
Definition at line 52 of file strcspn.c.
References strchr(), and strlen().
Referenced by strpbrk(), and strtok().
char* strerror | ( | int | errnum | ) |
Maps an error number to an error message string.
errnum | Error number being mapped |
The strerror function maps the error number in errnum to an error message string.
The implementation shall behave as if no library function calls the strerror function.
Definition at line 54 of file strerror.c.
size_t strlen | ( | const char * | s | ) |
Computes the length of a string.
*s | String having its length computed |
The strlen function computes the length of the string pointed to by s.
Definition at line 51 of file strlen.c.
Referenced by strcat(), strcmp(), strcpy(), strcspn(), strncat(), strncmp(), strncpy(), strrchr(), and strstr().
char* strncat | ( | char * | s1, |
const char * | s2, | ||
size_t | n | ||
) |
Concatenates two strings, appending no more than n characters.
*s1 | Destination string |
*s2 | String to be appended |
n | Maximum number of characters to append |
The strncat function appends not more than n characters (a null character and characters that follow it are not appended) from the array pointed to by s2 to the end of the string pointed to by s1. The initial character of s2 overwrites the null character at the end of s1. A terminating null character is always appended to the result. If copying takes place between objects that overlap, the behavior is undefined.
Definition at line 62 of file strncat.c.
References memmove(), and strlen().
int strncmp | ( | const char * | s1, |
const char * | s2, | ||
size_t | n | ||
) |
Compares the strings pointed to be s1 and s2.
*s1 | The first string to be compared |
*s2 | The second string to be compared |
n | Maximum number of characters to be compared |
The strncmp function compares note more than n characters (characters that follow a null character are not compared) from the array pointed to by s1 to the array pointed to by s2.
>0 | s1 is greater than s2 or no comparison could be made |
0 | s1 is equal to s2 |
<0 | s1 is less than s2 |
Definition at line 56 of file strncmp.c.
References memcmp(), and strlen().
Referenced by strstr().
char* strncpy | ( | char * | s1, |
const char * | s2, | ||
size_t | n | ||
) |
Copies no more than n characters with null terminator from s2 to s1.
*s1 | The destination array |
*s2 | The source string |
n | Maximum number of characters to copy |
The strncpy function copies not more than n characters (characters that follow a null character are not copied) from the array pointed to by s2 to the array pointed to be s1. If the array pointed to by s2 is a string that is shorter than n characters, null characters are appended to the copy in the array pointed to by s1, until n characters in all have been written.
Definition at line 58 of file strncpy.c.
References memmove(), memset(), strcpy(), and strlen().
char* strpbrk | ( | const char * | s1, |
const char * | s2 | ||
) |
Locate the first occurrence of any of s2 in s1.
*s1 | String being searched |
*s2 | String of characters to search for |
The strpbrk function locates the first occurrence in the string pointed to by s1 of any character from the string pointed to by s2.
Definition at line 51 of file strpbrk.c.
References NULL, and strcspn().
char* strrchr | ( | const char * | s, |
int | c | ||
) |
Locate the last occurrence of a character in a string.
*s | String being searched |
c | Character to find |
The strrchr function locates the last occurrence of c (converted to a char) in the string pointed to by s. The terminating null character is considered to be a part of the string.
NULL | The character does not occur in the string |
Definition at line 53 of file strrchr.c.
References NULL, and strlen().
size_t strspn | ( | const char * | s1, |
const char * | s2 | ||
) |
Find the length of the span of characters in s2 in s1.
*s1 | String being searched |
*s2 | String of characters in the span being found |
The strspn function computes the length of the maximum initial segment of the string pointed to by s1 which consists entirely of characters from the string pointed to by s2.
Definition at line 52 of file strspn.c.
References strchr().
Referenced by strtok().
char* strstr | ( | const char * | s1, |
const char * | s2 | ||
) |
Locate the first occurrence of a string in a another string.
*s1 | String being searched |
*s2 | String being found |
The strstr function locates the first occurrence in the string pointed to by s1 of the sequence of characters (excluding the terminating null character) in the string pointed to by s2.
NULL | The sequence in s2 was not found in s1 |
Definition at line 53 of file strstr.c.
References NULL, strchr(), strlen(), and strncmp().
char* strtok | ( | char * | s1, |
const char * | s2 | ||
) |
Breaks a string into a sequence of tokens split on a given delimiter.
*s1 | String to be tokenized |
*s2 | Separator string used to delimit tokens |
A sequence of calls to the strtok functions breaks the string pointed to by s1 into a sequence of tokens, each of which is delimited by a character from the string pointed to by s2. The first call in the sequence has s1 as its first argument, and is followed by calls with a null pointer as their first argument. The separator string pointed to by s2 may be different from call to call.
The first call in the sequence searches the string pointed to by s1 for the first character that is not contained in the current separator string pointed to by s2. If no such character is found, then there are no tokens in the string pointed to by s1 and the strtok function returns a null pointer. If such a character is found, it is the start of the first token.
The strtok function then searches from there for a character that is contained in the current separator string. If no such character is found, the current token extends to the end of the string pointed to by s1, and subsequent searches for a token will return a null pointer. If such a character is found, it is overwritten by a null character, which terminates the current token. The strtok function saves a pointer to the following character, from which the next search for a token will start.
Each subsequent call, with a null pointer as the value of the first argument, starts searching from the saved pointer and behaves as described above.
The implementation shall behave as if no library function calls the strtok function.
NULL | No token was found |
Definition at line 77 of file strtok.c.
References NULL, strcspn(), and strspn().