.TH ": Strings" 3 "24 Jun 2019" "Version 2.0.0" "avr-libc" \" -*- nroff -*- .ad l .nh .SH NAME : Strings \- .SS "Defines" .in +1c .ti -1c .RI "#define \fB_FFS\fP(x)" .br .in -1c .SS "Functions" .in +1c .ti -1c .RI "int \fBffs\fP (int __val)" .br .ti -1c .RI "int \fBffsl\fP (long __val)" .br .ti -1c .RI "__extension__ int \fBffsll\fP (long long __val)" .br .ti -1c .RI "void * \fBmemccpy\fP (void *, const void *, int, size_t)" .br .ti -1c .RI "void * \fBmemchr\fP (const void *, int, size_t) __ATTR_PURE__" .br .ti -1c .RI "int \fBmemcmp\fP (const void *, const void *, size_t) __ATTR_PURE__" .br .ti -1c .RI "void * \fBmemcpy\fP (void *, const void *, size_t)" .br .ti -1c .RI "void * \fBmemmem\fP (const void *, size_t, const void *, size_t) __ATTR_PURE__" .br .ti -1c .RI "void * \fBmemmove\fP (void *, const void *, size_t)" .br .ti -1c .RI "void * \fBmemrchr\fP (const void *, int, size_t) __ATTR_PURE__" .br .ti -1c .RI "void * \fBmemset\fP (void *, int, size_t)" .br .ti -1c .RI "char * \fBstrcat\fP (char *, const char *)" .br .ti -1c .RI "char * \fBstrchr\fP (const char *, int) __ATTR_PURE__" .br .ti -1c .RI "char * \fBstrchrnul\fP (const char *, int) __ATTR_PURE__" .br .ti -1c .RI "int \fBstrcmp\fP (const char *, const char *) __ATTR_PURE__" .br .ti -1c .RI "char * \fBstrcpy\fP (char *, const char *)" .br .ti -1c .RI "int \fBstrcasecmp\fP (const char *, const char *) __ATTR_PURE__" .br .ti -1c .RI "char * \fBstrcasestr\fP (const char *, const char *) __ATTR_PURE__" .br .ti -1c .RI "size_t \fBstrcspn\fP (const char *__s, const char *__reject) __ATTR_PURE__" .br .ti -1c .RI "char * \fBstrdup\fP (const char *s1)" .br .ti -1c .RI "size_t \fBstrlcat\fP (char *, const char *, size_t)" .br .ti -1c .RI "size_t \fBstrlcpy\fP (char *, const char *, size_t)" .br .ti -1c .RI "size_t \fBstrlen\fP (const char *) __ATTR_PURE__" .br .ti -1c .RI "char * \fBstrlwr\fP (char *)" .br .ti -1c .RI "char * \fBstrncat\fP (char *, const char *, size_t)" .br .ti -1c .RI "int \fBstrncmp\fP (const char *, const char *, size_t) __ATTR_PURE__" .br .ti -1c .RI "char * \fBstrncpy\fP (char *, const char *, size_t)" .br .ti -1c .RI "int \fBstrncasecmp\fP (const char *, const char *, size_t) __ATTR_PURE__" .br .ti -1c .RI "size_t \fBstrnlen\fP (const char *, size_t) __ATTR_PURE__" .br .ti -1c .RI "char * \fBstrpbrk\fP (const char *__s, const char *__accept) __ATTR_PURE__" .br .ti -1c .RI "char * \fBstrrchr\fP (const char *, int) __ATTR_PURE__" .br .ti -1c .RI "char * \fBstrrev\fP (char *)" .br .ti -1c .RI "char * \fBstrsep\fP (char **, const char *)" .br .ti -1c .RI "size_t \fBstrspn\fP (const char *__s, const char *__accept) __ATTR_PURE__" .br .ti -1c .RI "char * \fBstrstr\fP (const char *, const char *) __ATTR_PURE__" .br .ti -1c .RI "char * \fBstrtok\fP (char *, const char *)" .br .ti -1c .RI "char * \fBstrtok_r\fP (char *, const char *, char **)" .br .ti -1c .RI "char * \fBstrupr\fP (char *)" .br .in -1c .SH "Detailed Description" .PP .PP .nf #include .fi .PP .PP The string functions perform string operations on NULL terminated strings. .PP \fBNote:\fP .RS 4 If the strings you are working on resident in program space (flash), you will need to use the string functions described in \fB: Program Space Utilities\fP. .RE .PP .SH "Define Documentation" .PP .SS "#define _FFS(x)"This macro finds the first (least significant) bit set in the input value. .PP This macro is very similar to the function \fBffs()\fP except that it evaluates its argument at compile-time, so it should only be applied to compile-time constant expressions where it will reduce to a constant itself. Application of this macro to expressions that are not constant at compile-time is not recommended, and might result in a huge amount of code generated. .PP \fBReturns:\fP .RS 4 The \fB_FFS()\fP macro returns the position of the first (least significant) bit set in the word val, or 0 if no bits are set. The least significant bit is position 1. Only 16 bits of argument are evaluted. .RE .PP .SH "Function Documentation" .PP .SS "int ffs (int val)" .PP This function finds the first (least significant) bit set in the input value. \fBReturns:\fP .RS 4 The \fBffs()\fP function returns the position of the first (least significant) bit set in the word val, or 0 if no bits are set. The least significant bit is position 1. .RE .PP \fBNote:\fP .RS 4 For expressions that are constant at compile time, consider using the \fB_FFS\fP macro instead. .RE .PP .SS "int ffsl (long __val)" .PP Same as \fBffs()\fP, for an argument of type long. .SS "int ffsll (long long __val)" .PP Same as \fBffs()\fP, for an argument of type long long. .SS "void * memccpy (void * dest, const void * src, int val, size_t len)" .PP Copy memory area. The \fBmemccpy()\fP function copies no more than \fClen\fP bytes from memory area \fCsrc\fP to memory area \fCdest\fP, stopping when the character \fCval\fP is found. .PP \fBReturns:\fP .RS 4 The \fBmemccpy()\fP function returns a pointer to the next character in \fCdest\fP after \fCval\fP, or NULL if \fCval\fP was not found in the first \fClen\fP characters of \fCsrc\fP. .RE .PP .SS "void * memchr (const void * src, int val, size_t len)" .PP Scan memory for a character. The \fBmemchr()\fP function scans the first len bytes of the memory area pointed to by src for the character val. The first byte to match val (interpreted as an unsigned character) stops the operation. .PP \fBReturns:\fP .RS 4 The \fBmemchr()\fP function returns a pointer to the matching byte or NULL if the character does not occur in the given memory area. .RE .PP .SS "int memcmp (const void * s1, const void * s2, size_t len)" .PP Compare memory areas. The \fBmemcmp()\fP function compares the first len bytes of the memory areas s1 and s2. The comparision is performed using unsigned char operations. .PP \fBReturns:\fP .RS 4 The \fBmemcmp()\fP function returns an integer less than, equal to, or greater than zero if the first len bytes of s1 is found, respectively, to be less than, to match, or be greater than the first len bytes of s2. .RE .PP \fBNote:\fP .RS 4 Be sure to store the result in a 16 bit variable since you may get incorrect results if you use an unsigned char or char due to truncation. .RE .PP \fBWarning:\fP .RS 4 This function is not -mint8 compatible, although if you only care about testing for equality, this function should be safe to use. .RE .PP .SS "void * memcpy (void * dest, const void * src, size_t len)" .PP Copy a memory area. The \fBmemcpy()\fP function copies len bytes from memory area src to memory area dest. The memory areas may not overlap. Use \fBmemmove()\fP if the memory areas do overlap. .PP \fBReturns:\fP .RS 4 The \fBmemcpy()\fP function returns a pointer to dest. .RE .PP .SS "void * memmem (const void * s1, size_t len1, const void * s2, size_t len2)"The \fBmemmem()\fP function finds the start of the first occurrence of the substring \fCs2\fP of length \fClen2\fP in the memory area \fCs1\fP of length \fClen1\fP. .PP \fBReturns:\fP .RS 4 The \fBmemmem()\fP function returns a pointer to the beginning of the substring, or \fCNULL\fP if the substring is not found. If \fClen2\fP is zero, the function returns \fCs1\fP. .RE .PP .SS "void * memmove (void * dest, const void * src, size_t len)" .PP Copy memory area. The \fBmemmove()\fP function copies len bytes from memory area src to memory area dest. The memory areas may overlap. .PP \fBReturns:\fP .RS 4 The \fBmemmove()\fP function returns a pointer to dest. .RE .PP .SS "void * memrchr (const void * src, int val, size_t len)"The \fBmemrchr()\fP function is like the \fBmemchr()\fP function, except that it searches backwards from the end of the \fClen\fP bytes pointed to by \fCsrc\fP instead of forwards from the front. (Glibc, GNU extension.) .PP \fBReturns:\fP .RS 4 The \fBmemrchr()\fP function returns a pointer to the matching byte or \fCNULL\fP if the character does not occur in the given memory area. .RE .PP .SS "void * memset (void * dest, int val, size_t len)" .PP Fill memory with a constant byte. The \fBmemset()\fP function fills the first len bytes of the memory area pointed to by dest with the constant byte val. .PP \fBReturns:\fP .RS 4 The \fBmemset()\fP function returns a pointer to the memory area dest. .RE .PP .SS "int strcasecmp (const char * s1, const char * s2)" .PP Compare two strings ignoring case. The \fBstrcasecmp()\fP function compares the two strings \fCs1\fP and \fCs2\fP, ignoring the case of the characters. .PP \fBReturns:\fP .RS 4 The \fBstrcasecmp()\fP function returns an integer less than, equal to, or greater than zero if \fCs1\fP is found, respectively, to be less than, to match, or be greater than \fCs2\fP. A consequence of the ordering used by \fBstrcasecmp()\fP is that if \fCs1\fP is an initial substring of \fCs2\fP, then \fCs1\fP is considered to be 'less than' \fCs2\fP. .RE .PP .SS "char * strcasestr (const char * s1, const char * s2)"The \fBstrcasestr()\fP function finds the first occurrence of the substring \fCs2\fP in the string \fCs1\fP. This is like \fBstrstr()\fP, except that it ignores case of alphabetic symbols in searching for the substring. (Glibc, GNU extension.) .PP \fBReturns:\fP .RS 4 The \fBstrcasestr()\fP function returns a pointer to the beginning of the substring, or \fCNULL\fP if the substring is not found. If \fCs2\fP points to a string of zero length, the function returns \fCs1\fP. .RE .PP .SS "char * strcat (char * dest, const char * src)" .PP Concatenate two strings. The \fBstrcat()\fP function appends the src string to the dest string overwriting the '\\0' character at the end of dest, and then adds a terminating '\\0' character. The strings may not overlap, and the dest string must have enough space for the result. .PP \fBReturns:\fP .RS 4 The \fBstrcat()\fP function returns a pointer to the resulting string dest. .RE .PP .SS "char * strchr (const char * src, int val)" .PP Locate character in string. The \fBstrchr()\fP function returns a pointer to the first occurrence of the character \fCval\fP in the string \fCsrc\fP. .PP Here 'character' means 'byte' - these functions do not work with wide or multi-byte characters. .PP \fBReturns:\fP .RS 4 The \fBstrchr()\fP function returns a pointer to the matched character or \fCNULL\fP if the character is not found. .RE .PP .SS "char * strchrnul (const char * s, int c)"The \fBstrchrnul()\fP function is like \fBstrchr()\fP except that if \fCc\fP is not found in \fCs\fP, then it returns a pointer to the null byte at the end of \fCs\fP, rather than \fCNULL\fP. (Glibc, GNU extension.) .PP \fBReturns:\fP .RS 4 The \fBstrchrnul()\fP function returns a pointer to the matched character, or a pointer to the null byte at the end of \fCs\fP (i.e., \fCs+strlen\fP(s)) if the character is not found. .RE .PP .SS "int strcmp (const char * s1, const char * s2)" .PP Compare two strings. The \fBstrcmp()\fP function compares the two strings \fCs1\fP and \fCs2\fP. .PP \fBReturns:\fP .RS 4 The \fBstrcmp()\fP function returns an integer less than, equal to, or greater than zero if \fCs1\fP is found, respectively, to be less than, to match, or be greater than \fCs2\fP. A consequence of the ordering used by \fBstrcmp()\fP is that if \fCs1\fP is an initial substring of \fCs2\fP, then \fCs1\fP is considered to be 'less than' \fCs2\fP. .RE .PP .SS "char * strcpy (char * dest, const char * src)" .PP Copy a string. The \fBstrcpy()\fP function copies the string pointed to by src (including the terminating '\\0' character) to the array pointed to by dest. The strings may not overlap, and the destination string dest must be large enough to receive the copy. .PP \fBReturns:\fP .RS 4 The \fBstrcpy()\fP function returns a pointer to the destination string dest. .RE .PP \fBNote:\fP .RS 4 If the destination string of a \fBstrcpy()\fP is not large enough (that is, if the programmer was stupid/lazy, and failed to check the size before copying) then anything might happen. Overflowing fixed length strings is a favourite cracker technique. .RE .PP .SS "size_t strcspn (const char * s, const char * reject)"The \fBstrcspn()\fP function calculates the length of the initial segment of \fCs\fP which consists entirely of characters not in \fCreject\fP. .PP \fBReturns:\fP .RS 4 The \fBstrcspn()\fP function returns the number of characters in the initial segment of \fCs\fP which are not in the string \fCreject\fP. The terminating zero is not considered as a part of string. .RE .PP .SS "char * strdup (const char * s1)" .PP Duplicate a string. The \fBstrdup()\fP function allocates memory and copies into it the string addressed by s1, including the terminating null character. .PP \fBWarning:\fP .RS 4 The \fBstrdup()\fP function calls \fBmalloc()\fP to allocate the memory for the duplicated string! The user is responsible for freeing the memory by calling \fBfree()\fP. .RE .PP \fBReturns:\fP .RS 4 The \fBstrdup()\fP function returns a pointer to the resulting string dest. If \fBmalloc()\fP cannot allocate enough storage for the string, \fBstrdup()\fP will return NULL. .RE .PP \fBWarning:\fP .RS 4 Be sure to check the return value of the \fBstrdup()\fP function to make sure that the function has succeeded in allocating the memory! .RE .PP .SS "size_t strlcat (char * dst, const char * src, size_t siz)" .PP Concatenate two strings. Appends \fCsrc\fP to string \fCdst\fP of size \fCsiz\fP (unlike \fBstrncat()\fP, \fCsiz\fP is the full size of \fCdst\fP, not space left). At most \fCsiz-1\fP characters will be copied. Always NULL terminates (unless \fCsiz\fP <= \fCstrlen(dst)\fP). .PP \fBReturns:\fP .RS 4 The \fBstrlcat()\fP function returns strlen(src) + MIN(siz, strlen(initial dst)). If retval >= siz, truncation occurred. .RE .PP Appends src to string dst of size siz (unlike \fBstrncat()\fP, siz is the full size of dst, not space left). At most siz-1 characters will be copied. Always NULL terminates (unless siz <= strlen(dst)). .PP \fBReturns:\fP .RS 4 The \fBstrlcat()\fP function returns strlen(src) + MIN(siz, strlen(initial dst)). If retval >= siz, truncation occurred. .RE .PP .SS "size_t strlcpy (char * dst, const char * src, size_t siz)" .PP Copy a string. Copy \fCsrc\fP to string \fCdst\fP of size \fCsiz\fP. At most \fCsiz-1\fP characters will be copied. Always NULL terminates (unless \fCsiz\fP == 0). .PP \fBReturns:\fP .RS 4 The \fBstrlcpy()\fP function returns strlen(src). If retval >= siz, truncation occurred. .RE .PP Copy src to string dst of size siz. At most siz-1 characters will be copied. Always NULL terminates (unless siz == 0). .PP \fBReturns:\fP .RS 4 The \fBstrlcpy()\fP function returns strlen(src). If retval >= siz, truncation occurred. .RE .PP .SS "size_t strlen (const char * src)" .PP Calculate the length of a string. The \fBstrlen()\fP function calculates the length of the string src, not including the terminating '\\0' character. .PP \fBReturns:\fP .RS 4 The \fBstrlen()\fP function returns the number of characters in src. .RE .PP .SS "char * strlwr (char * s)" .PP Convert a string to lower case. The \fBstrlwr()\fP function will convert a string to lower case. Only the upper case alphabetic characters [A .. Z] are converted. Non-alphabetic characters will not be changed. .PP \fBReturns:\fP .RS 4 The \fBstrlwr()\fP function returns a pointer to the converted string. .RE .PP .SS "int strncasecmp (const char * s1, const char * s2, size_t len)" .PP Compare two strings ignoring case. The \fBstrncasecmp()\fP function is similar to \fBstrcasecmp()\fP, except it only compares the first \fClen\fP characters of \fCs1\fP. .PP \fBReturns:\fP .RS 4 The \fBstrncasecmp()\fP function returns an integer less than, equal to, or greater than zero if \fCs1\fP (or the first \fClen\fP bytes thereof) is found, respectively, to be less than, to match, or be greater than \fCs2\fP. A consequence of the ordering used by \fBstrncasecmp()\fP is that if \fCs1\fP is an initial substring of \fCs2\fP, then \fCs1\fP is considered to be 'less than' \fCs2\fP. .RE .PP .SS "char * strncat (char * dest, const char * src, size_t len)" .PP Concatenate two strings. The \fBstrncat()\fP function is similar to \fBstrcat()\fP, except that only the first n characters of src are appended to dest. .PP \fBReturns:\fP .RS 4 The \fBstrncat()\fP function returns a pointer to the resulting string dest. .RE .PP .SS "int strncmp (const char * s1, const char * s2, size_t len)" .PP Compare two strings. The \fBstrncmp()\fP function is similar to \fBstrcmp()\fP, except it only compares the first (at most) n characters of s1 and s2. .PP \fBReturns:\fP .RS 4 The \fBstrncmp()\fP function returns an integer less than, equal to, or greater than zero if s1 (or the first n bytes thereof) is found, respectively, to be less than, to match, or be greater than s2. .RE .PP .SS "char * strncpy (char * dest, const char * src, size_t len)" .PP Copy a string. The \fBstrncpy()\fP function is similar to \fBstrcpy()\fP, except that not more than n bytes of src are copied. Thus, if there is no null byte among the first n bytes of src, the result will not be null-terminated. .PP In the case where the length of src is less than that of n, the remainder of dest will be padded with nulls. .PP \fBReturns:\fP .RS 4 The \fBstrncpy()\fP function returns a pointer to the destination string dest. .RE .PP .SS "size_t strnlen (const char * src, size_t len)" .PP Determine the length of a fixed-size string. The strnlen function returns the number of characters in the string pointed to by src, not including the terminating '\\0' character, but at most len. In doing this, strnlen looks only at the first len characters at src and never beyond src+len. .PP \fBReturns:\fP .RS 4 The strnlen function returns strlen(src), if that is less than len, or len if there is no '\\0' character among the first len characters pointed to by src. .RE .PP .SS "char * strpbrk (const char * s, const char * accept)"The \fBstrpbrk()\fP function locates the first occurrence in the string \fCs\fP of any of the characters in the string \fCaccept\fP. .PP \fBReturns:\fP .RS 4 The \fBstrpbrk()\fP function returns a pointer to the character in \fCs\fP that matches one of the characters in \fCaccept\fP, or \fCNULL\fP if no such character is found. The terminating zero is not considered as a part of string: if one or both args are empty, the result will be \fCNULL\fP. .RE .PP .SS "char * strrchr (const char * src, int val)" .PP Locate character in string. The \fBstrrchr()\fP function returns a pointer to the last occurrence of the character val in the string src. .PP Here 'character' means 'byte' - these functions do not work with wide or multi-byte characters. .PP \fBReturns:\fP .RS 4 The \fBstrrchr()\fP function returns a pointer to the matched character or NULL if the character is not found. .RE .PP .SS "char * strrev (char * s)" .PP Reverse a string. The \fBstrrev()\fP function reverses the order of the string. .PP \fBReturns:\fP .RS 4 The \fBstrrev()\fP function returns a pointer to the beginning of the reversed string. .RE .PP .SS "char * strsep (char ** sp, const char * delim)" .PP Parse a string into tokens. The \fBstrsep()\fP function locates, in the string referenced by \fC*sp\fP, the first occurrence of any character in the string \fCdelim\fP (or the terminating '\\0' character) and replaces it with a '\\0'. The location of the next character after the delimiter character (or \fCNULL\fP, if the end of the string was reached) is stored in \fC*sp\fP. An ``empty'' field, i.e. one caused by two adjacent delimiter characters, can be detected by comparing the location referenced by the pointer returned in \fC*sp\fP to '\\0'. .PP \fBReturns:\fP .RS 4 The \fBstrsep()\fP function returns a pointer to the original value of \fC*sp\fP. If \fC*sp\fP is initially \fCNULL\fP, \fBstrsep()\fP returns \fCNULL\fP. .RE .PP .SS "size_t strspn (const char * s, const char * accept)"The \fBstrspn()\fP function calculates the length of the initial segment of \fCs\fP which consists entirely of characters in \fCaccept\fP. .PP \fBReturns:\fP .RS 4 The \fBstrspn()\fP function returns the number of characters in the initial segment of \fCs\fP which consist only of characters from \fCaccept\fP. The terminating zero is not considered as a part of string. .RE .PP .SS "char * strstr (const char * s1, const char * s2)" .PP Locate a substring. The \fBstrstr()\fP function finds the first occurrence of the substring \fCs2\fP in the string \fCs1\fP. The terminating '\\0' characters are not compared. .PP \fBReturns:\fP .RS 4 The \fBstrstr()\fP function returns a pointer to the beginning of the substring, or \fCNULL\fP if the substring is not found. If \fCs2\fP points to a string of zero length, the function returns \fCs1\fP. .RE .PP .SS "char * strtok (char * s, const char * delim)" .PP Parses the string s into tokens. strtok parses the string s into tokens. The first call to strtok should have s as its first argument. Subsequent calls should have the first argument set to NULL. If a token ends with a delimiter, this delimiting character is overwritten with a '\\0' and a pointer to the next character is saved for the next call to strtok. The delimiter string delim may be different for each call. .PP \fBReturns:\fP .RS 4 The \fBstrtok()\fP function returns a pointer to the next token or NULL when no more tokens are found. .RE .PP \fBNote:\fP .RS 4 \fBstrtok()\fP is NOT reentrant. For a reentrant version of this function see \fC\fBstrtok_r()\fP\fP. .RE .PP .SS "char * strtok_r (char * string, const char * delim, char ** last)" .PP Parses string into tokens. strtok_r parses string into tokens. The first call to strtok_r should have string as its first argument. Subsequent calls should have the first argument set to NULL. If a token ends with a delimiter, this delimiting character is overwritten with a '\\0' and a pointer to the next character is saved for the next call to strtok_r. The delimiter string \fCdelim\fP may be different for each call. \fClast\fP is a user allocated char* pointer. It must be the same while parsing the same string. strtok_r is a reentrant version of \fBstrtok()\fP. .PP \fBReturns:\fP .RS 4 The \fBstrtok_r()\fP function returns a pointer to the next token or NULL when no more tokens are found. .RE .PP .SS "char * strupr (char * s)" .PP Convert a string to upper case. The \fBstrupr()\fP function will convert a string to upper case. Only the lower case alphabetic characters [a .. z] are converted. Non-alphabetic characters will not be changed. .PP \fBReturns:\fP .RS 4 The \fBstrupr()\fP function returns a pointer to the converted string. The pointer is the same as that passed in since the operation is perform in place. .RE .PP .SH "Author" .PP Generated automatically by Doxygen for avr-libc from the source code.