Table of Contents

STRING.H

MACROS

NULL ((void*)(0)) pointer to nothing

TYPES

size_t unsigned int

COPYING

void bcopy(const void *src, void *dst, size_t n)

Same as memmove(dst, src, n)

void *memccpy(void *dst, void *src, int c, size_t n)

Copy at most n bytes from memory area src to memory area dst stopping early after the first occurrence of char c is copied.

Returns 0 if char c not seen or a pointer in dst to the char following copied c.

void *memcpy(void *dst, const void *src, size_t n)

Copy n bytes from memory area src to memory area dst. Behaviour is undefined if the src and dst areas overlap (see memmove for this case). Returns dst.

void *memmove(void *dst, const void *src, size_t n)

Copy n bytes from memory area src to memory area dst. The copy completes correctly even if the areas overlap. Returns dst.

char *_memstrcpy_(void *p, char *s, size_t n)

At most n chars from string s are copied to memory area p. The terminating NUL in s is not copied to p. Returns pointer to the first char in s not copied to p.

void *memswap(void *s1, void *s2, size_t n)

Swap the n bytes in memory areas s1 and s2. Return s1.

char *stpcpy(char *dst, char *src)

Copy string src to string dst and return a pointer to the terminating NUL in dst.

char *stpncpy(char *dst, char *src, size_t n)

Copy at most n chars from string src to string dst and return a pointer to the first copied NUL in dst or &dst[n] if n was exhausted first. Pad dst with zeroes so that n chars are always written to dst.

Note that dst is not NUL terminated if strlen(src) > = n.

char *strcpy(char *dst, const char *src)

Copy string src to string dst. Return dst.

char *strdup(char *s)

Allocate sufficient memory from the heap to hold a copy of string s and then copy s into the allocated block. Return a pointer to the allocated memory. This memory must be released with free().

If the allocation fails, 0 is returned, carry flag is set and errno is set to:

  • [ENOMEM] insufficient memory

size_t strlcpy(char *dst, char *src, size_t n)

Copy at most n chars from string src to string dst where n includes space for a terminating NUL. String dst is always NUL terminated except when n is 0, in which case dst is not modified. Returns strlen(src).

char *strncpy(char *dst, const char *src, size_t n)

Copy at most n chars from string src to string dst. Pad dst with zeroes so that n bytes are always written to dst. Note that if strlen(src) > = n, dst will not be NUL terminated. Return dst.

char *strndup(char *s, size_t n)

Allocate min(n+1, strlen(s)+1) bytes from the heap and then copy at most n chars from string s to the allocated block along with a terminating NUL. Return a pointer to the allocated memory. This memory must be released with free().

If the allocation fails, 0 is returned, carry flag is set and errno is set to:

  • [ENOMEM] insufficient memory

CONCATENATION

char *strcat(char *dst, const char *src)

Append string src to string dst. Returns dst.

size_t strlcat(char *dst, char *src, size_t n)

Append string src to string dst such that the total length of dst is no more than n chars including terminating NUL. Strinh dst is unaltered if its length is already > = n. Returns strlen(src)+strlen(original dst); this is the total buffer size required of dst to store the entire result of concatenation not including terminating NUL.

char *strncat(char *dst, const char *src, size_t n)

Append at most n chars from string src to string dst. String dst is always NUL terminated. Returns dst.

COMPARISON

int bcmp(void *s1, void *s2, size_t n)

Same as memcmp(s1, s2, n)

int memcmp(const void *s1, const void *s2, size_t n)

Compare at most n bytes of memory area s1 to memory area s2. Return when first differing byte is found with result holding same sign as (*s1-*s2).

int strcasecmp(char *s1, char *s2)

Perform caseless compare of string s1 to string s2. Return when first differing char is found with result holding the same sign as (tolower(*s1)-tolower(*s2)).

int strcmp(const char *s1, const char *s2)

Compare string s1 to string s2. Return when first differing char is found with result holding the same sign as (*s1-*s2).

int strcoll(const char *s1, const char *s2)

Compare string s1 to string s2. Return when first differing char is found with result holding the same sign as (*s1-*s2). Use alternate locale's comparison function to perform the comparison.

int stricmp(char *s1, char *s2)

Same as strcasecmp(s1, s2)

int strncasecmp(char *s1, char *s2, size_t n)

Perform caseless compare of at most n chars of string s1 to string s2. Return when first differing char is found with result holding the same sign as (tolower(*s1)-tolower(*s2)).

int strncmp(const char *s1, const char *s2, size_t n)

Compare at most n chars of string s1 to string s2. Return when first differing char is found with result holding the same sign as (*s1-*s2).

int strnicmp(char *s1, char *s2, size_t n)

Same as strncasecmp(s1, s2)

size_t strxfrm(char *dst, const char *src, size_t n)

Transform at most n-1 chars from string src according to the alternate locale and write the resulting chars into string dst. If n > 0 string dst is always NUL terminated. Following transformation string dst can be used with C library functions for comparison purposes without having to consider locale. Returns length of resulting string dst.

If dst = 0 the transformation is run but the result string is not written. The return value reflects the length of the would-be result less the terminating NUL char.

SEARCH

char *index(char *s, int c)

Same as strchr(s, c)

void *memchr(const void *s, int c, size_t n)

Return a pointer to the first occurrence of byte c in the first n bytes of memory area s. Returns 0 if byte c is not found.

void *memmem(void *haystack, size_t haystack_len, void *needle, size_t needle_len)

Returns pointer to the first occurrence of memory block needle in memory area haystack. If needle_len = 0 returns haystack. If memory area needle is not found or haystack_len < needle_len returns 0.

void *memrchr(void *s, int c, size_t n)

Return a pointer to the last occurrence of byte c in the first n bytes of memory area s. Returns 0 if byte c is not found.

void *rawmemchr(const void *mem, int c)

Returns pointer to the first occurrence of byte c in memory beginning at address mem. The search will examine the entire 64k memory space if needed.

char *rindex(char *s, int c)

Same as strrchr(s, c)

char *strchr(const char *s, int c)

Return pointer to first occurrence of char c in string s or 0 if char c is not found.

char *strchrnul(char *s, int c)

Return pointer to first occurrence of char c in string s or a pointer to the terminating NUL in s if char c is not found.

size_t strcspn(const char *s1, const char *s2)

Return length of prefix of string s1 not containing any chars from string s2.

char *strnchr(char *s, size_t n, int c)

Return pointer to first occurrence of char c among the first n chars of string s or 0 if char c is not found.

char *strpbrk(const char *s1, const char *s2)

Return pointer to first occurrence of any char from string s2 in string s1. Return 0 if no chars from string s2 can be found in string s1.

char *strrchr(const char *s, int c)

Return pointer to last occurrence of char c in string s or 0 if char c is not found.

size_t strrcspn(char *s, char *set)

Returns the number of leading chars in s up to and including the last occurrence in s of a char from set. If set is the empty string, strlen(s) is returned. If no chars from s are found in s, 0 is returned.

size_t strrspn(char *s, char *set)

Returns the number of leading chars in s up to and including the last occurrence of a char not in set. If set is the empty string, strlen(s) is returned. If all chars of s are in set, returns 0.

char *strsep(char **s, char *delim)

If *s is 0, returns 0 and does nothing else. Otherwise finds the first token in the string *s where tokens are delimited by symbols in the string delim. This token is terminated by overwriting the delimiter with a NUL byte and *s is updated to point past the token. In case no delimiter was found the token is taken to be the entire string *s, and *s is made 0.

Note that the empty token (””) will be returned if two delimiter chars appear in sequence in *s.

size_t strspn(const char *s1, const char *s2)

Return length of prefix of string s1 containing chars from string s2.

char *strstr(const char *s1, const char *s2)

Return pointer in s1 to the first occurrence of string s2. Returns 0 if substring s2 is not found.

char *strtok(char *s, const char *delim)

Return the next token from the string being traversed using string delim as a list of delimiter chars. If s is not 0 store its address in internal static storage as the string being traversed, otherwise continue using the last stored string.

When looking for the next token first skip over any leading delimiter chars and then take that point as the start of the token. Find the end of the token by looking for the next delimiter char. Overwrite that char with NUL to terminate the token and then store the next address after the NUL in internal storage as the start of the string to use in the next call.

If the end of the internal string is reached so that there are no more tokens, 0 is returned.

Note that this function is not reentrant.

char *strtok_r(char *s, const char *delim, char **last_s)

A reentrant version of strtok(). Instead of using an internal static variable to hold the string being scanned, it uses the user-supplied static variable *last_s.

MISCELLANEOUS

void bzero(void *mem, size_t n)

Same as memset(mem, 0, n)

int ffs(int i)

Return bit position of the least significant set bit in i. Bits are numbered from 1 to 16 from the right. If i = 0, return 0.

int ffsl(long i)

Return bit position of the least significant set bit in i. Bits are numbered from 1 to 32 from the right. If i = 0, return 0.

int ffsll(long long i)

(nightly build, sdcc)
Return bit position of the least significant set bit in i. Bits are numbered from 1 to 64 from the right. If i = 0, return 0.

char *_memlwr_(void *p, size_t n)

Apply tolower() to the n bytes at address p. Return p.

void *memset(void *s, int c, size_t n)

Fill memory from address s to s+n-1 with char c. Return s.

char *_memupr_(void *p, size_t n)

Apply toupper() to the n bytes at address p. Return p.

char *strerror(int errnum)

Return a string message corresponding to errnum. The string is owned by the library.

size_t strlen(const char *s)

Return the length of string s not including its terminating NUL.

char *strlwr(char *s)

Apply tolower() to each char in string s. Return s.

size_t strnlen(char *s, size_t n)

Return min(n, strlen(s)). Does not examine more than n chars in s.

char *strnset(char *s, int c, size_t n)

Replace at most the first n chars of string s with c. Return s.

char *strrev(char *s)

Reverse string s in place. Return s.

char *_strrstrip_(char *s)

Return pointer to first whitespace char of the trailing whitespace chars in s. If s consists entirely of whitespace, return s.

char *strrstrip(char *s)

Remove trailing whitespace of s by writing a NUL over the first whitespace char of the trailing whitespace chars in s. If s consists entirely of whitespace, s[0]=0. Return s.

char *strset(char *s, int c)

Replace all chars in s with c. Return s.

char *strstrip(char *s)

Return pointer to first non-whitespace char in s.

char *strupr(char *s)

Apply toupper() to each char in s. Return s.

 
libnew/string.txt · Last modified: 2016/05/12 19:04 by aralbrec
 
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki