Macro Definition Documentation

#define _FFS

(

x

)

This macro finds the first (least significant) bit set in the input value.

This macro is very similar to the function ffs() 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.

Returns

The _FFS() 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.

Function Documentation

int ffs

(

int

val

)

This function finds the first (least significant) bit set in the input value.

Returns

The ffs() 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.

Note

For expressions that are constant at compile time, consider using the _FFS macro instead.

The memccpy() function copies no more than len bytes from memory area src to memory area dest, stopping when the character val is found.

Returns

The memccpy() function returns a pointer to the next character in dest after val, or NULL if val was not found in the first len characters of src.

void * memchr

(

const void *

src,

int

val,

size_t

len

)

Scan memory for a character.

The memchr() 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.

Returns

The memchr() function returns a pointer to the matching byte or NULL if the character does not occur in the given memory area.

int memcmp

(

const void *

s1,

const void *

s2,

size_t

len

)

Compare memory areas.

The memcmp() function compares the first len bytes of the memory areas s1 and s2. The comparision is performed using unsigned char operations.

Returns

The memcmp() 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.

Note

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.

Warning

This function is not -mint8 compatible, although if you only care about testing for equality, this function should be safe to use.

void * memcpy

(

void *

dest,

const void *

src,

size_t

len

)

Copy a memory area.

The memcpy() function copies len bytes from memory area src to memory area dest. The memory areas may not overlap. Use memmove() if the memory areas do overlap.

The strcasecmp() function compares the two strings s1 and s2, ignoring the case of the characters.

Returns

The strcasecmp() function returns an integer less than, equal to, or greater than zero if s1 is found, respectively, to be less than, to match, or be greater than s2. A consequence of the ordering used by strcasecmp() is that if s1 is an initial substring of s2, then s1 is considered to be "less than" s2.

char * strcasestr

(

const char *

s1,

const char *

s2

)

The strcasestr() function finds the first occurrence of the substring s2 in the string s1. This is like strstr(), except that it ignores case of alphabetic symbols in searching for the substring. (Glibc, GNU extension.)

Returns

The strcasestr() function returns a pointer to the beginning of the substring, or NULL if the substring is not found. If s2 points to a string of zero length, the function returns s1.

char * strcat

(

char *

dest,

const char *

src

)

Concatenate two strings.

The strcat() 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.

The strcmp() function returns an integer less than, equal to, or greater than zero if s1 is found, respectively, to be less than, to match, or be greater than s2. A consequence of the ordering used by strcmp() is that if s1 is an initial substring of s2, then s1 is considered to be "less than" s2.

char * strcpy

(

char *

dest,

const char *

src

)

Copy a string.

The strcpy() 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.

Returns

The strcpy() function returns a pointer to the destination string dest.

Note

If the destination string of a strcpy() 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.

size_t strcspn

(

const char *

s,

const char *

reject

)

The strcspn() function calculates the length of the initial segment of s which consists entirely of characters not in reject.

Returns

The strcspn() function returns the number of characters in the initial segment of s which are not in the string reject. The terminating zero is not considered as a part of string.

char * strdup

(

const char *

s1

)

Duplicate a string.

The strdup() function allocates memory and copies into it the string addressed by s1, including the terminating null character.

Warning

The strdup() function calls malloc() to allocate the memory for the duplicated string! The user is responsible for freeing the memory by calling free().

Returns

The strdup() function returns a pointer to the resulting string dest. If malloc() cannot allocate enough storage for the string, strdup() will return NULL.

Warning

Be sure to check the return value of the strdup() function to make sure that the function has succeeded in allocating the memory!

size_t strlcat

(

char *

dst,

const char *

src,

size_t

siz

)

Concatenate two strings.

Appends src to string dst of size siz (unlike strncat(), 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)).

The strncasecmp() function returns an integer less than, equal to, or greater than zero if s1 (or the first len bytes thereof) is found, respectively, to be less than, to match, or be greater than s2. A consequence of the ordering used by strncasecmp() is that if s1 is an initial substring of s2, then s1 is considered to be "less than" s2.

char * strncat

(

char *

dest,

const char *

src,

size_t

len

)

Concatenate two strings.

The strncat() function is similar to strcat(), except that only the first n characters of src are appended to dest.

Returns

The strncat() function returns a pointer to the resulting string dest.

int strncmp

(

const char *

s1,

const char *

s2,

size_t

len

)

Compare two strings.

The strncmp() function is similar to strcmp(), except it only compares the first (at most) n characters of s1 and s2.

Returns

The strncmp() 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.

char * strncpy

(

char *

dest,

const char *

src,

size_t

len

)

Copy a string.

The strncpy() function is similar to strcpy(), 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.

In the case where the length of src is less than that of n, the remainder of dest will be padded with nulls.

Returns

The strncpy() function returns a pointer to the destination string dest.

size_t strnlen

(

const char *

src,

size_t

len

)

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.

Returns

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.

char * strpbrk

(

const char *

s,

const char *

accept

)

The strpbrk() function locates the first occurrence in the string s of any of the characters in the string accept.

Returns

The strpbrk() function returns a pointer to the character in s that matches one of the characters in accept, or NULL 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 NULL.

char * strrchr

(

const char *

src,

int

val

)

Locate character in string.

The strrchr() function returns a pointer to the last occurrence of the character val in the string src.

Here "character" means "byte" - these functions do not work with wide or multi-byte characters.

Returns

The strrchr() function returns a pointer to the matched character or NULL if the character is not found.

The strrev() function returns a pointer to the beginning of the reversed string.

char * strsep

(

char **

sp,

const char *

delim

)

Parse a string into tokens.

The strsep() function locates, in the string referenced by *sp, the first occurrence of any character in the string delim (or the terminating '\0' character) and replaces it with a '\0'. The location of the next character after the delimiter character (or NULL, if the end of the string was reached) is stored in *sp. 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 *sp to '\0'.

Returns

The strsep() function returns a pointer to the original value of *sp. If *sp is initially NULL, strsep() returns NULL.

size_t strspn

(

const char *

s,

const char *

accept

)

The strspn() function calculates the length of the initial segment of s which consists entirely of characters in accept.

Returns

The strspn() function returns the number of characters in the initial segment of s which consist only of characters from accept. The terminating zero is not considered as a part of string.

char * strstr

(

const char *

s1,

const char *

s2

)

Locate a substring.

The strstr() function finds the first occurrence of the substring s2 in the string s1. The terminating '\0' characters are not compared.

Returns

The strstr() function returns a pointer to the beginning of the substring, or NULL if the substring is not found. If s2 points to a string of zero length, the function returns s1.

char * strtok

(

char *

s,

const char *

delim

)

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.

Returns

The strtok() function returns a pointer to the next token or NULL when no more tokens are found.

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 delim may be different for each call. last is a user allocated char* pointer. It must be the same while parsing the same string. strtok_r is a reentrant version of strtok().

Returns

The strtok_r() function returns a pointer to the next token or NULL when no more tokens are found.

char * strupr

(

char *

s

)

Convert a string to upper case.

The strupr() 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.

Returns

The strupr() function returns a pointer to the converted string. The pointer is the same as that passed in since the operation is perform in place.