|
đź§µ str
Painfully common string utilities for C
|
Utilities and polyfills for C-style nil-terminated strings. More...
#include <stddef.h>Go to the source code of this file.
Functions | |
| void * | memccpy (void *restrict dest, const void *restrict src, int ch, size_t len) |
Copies up to len characters from src into dest, stopping early if the character ch is encountered. | |
| char * | strdup (const char *src) |
| Duplicates a nil-terminated string. | |
| char * | strndup (const char *src, size_t size) |
| Duplicates a nil-terminated string, up to a maximum length. | |
| char * | strzcpy (char dest[restrict static 1], const char src[restrict static 1], size_t len) |
| Similar to strncpy(), except result is always nil-terminated. | |
Utilities and polyfills for C-style nil-terminated strings.
| void * memccpy | ( | void *restrict | dest, |
| const void *restrict | src, | ||
| int | ch, | ||
| size_t | len ) |
Copies up to len characters from src into dest, stopping early if the character ch is encountered.
| [out] | dest | The memory location to copy characters into. |
| [in] | src | The memory location to copy characters from. |
| [in] | ch | The character which when encountered ends the copying. |
| [in] | len | The maximum number of characters to copy. |
ch was encountered, returns a pointer to the character following it; otherwise, returns a nil pointer.. dest and src are interpreted as unsigned char*, and ch is interpreted as unsigned char. | char * strdup | ( | const char * | src | ) |
Duplicates a nil-terminated string.
The returned string can be passed into free() to destroy it.
| src | The nil-terminated string to duplicate. |
| char * strndup | ( | const char * | src, |
| size_t | size ) |
Duplicates a nil-terminated string, up to a maximum length.
If a nil terminator is not encountered in the first size bytes, it is appended to the duplicated string.
The returned string can be passed into free() to destroy it.
| src | The nil-terminated string to duplicate. |
| size | The maximum number of bytes to copy from src. |
| char * strzcpy | ( | char | dest[restrict static 1], |
| const char | src[restrict static 1], | ||
| size_t | len ) |
Similar to strncpy(), except result is always nil-terminated.
More accurately, this is a more ergonomic form of memccpy that is specifically tailored to be used on nil-terminated C-strings.
Behavior is undefined if len is greater than the size of either dest or src, if dest and src overlap, or if either dest or src are nil pointers.
| [out] | dest | Pointer to the character buffer to copy into |
| [in] | src | Pointer to the character buffer to copy from |
| [in] | len | The maximum number of characters to copy |
dest; otherwise, the string was truncated, and a nil pointer. is returned. A nil pointer. will also be returned if len is 0.