ZstrDupN
ZstrDupN
Description
Duplicates a string up to the specified length. Creates a new null-terminated string by allocating memory and copying at most n characters from the source string.
Parameters
| Name | Direction | Description |
|---|---|---|
src |
in | Source string to duplicate. |
n |
in | Maximum number of characters to copy. |
Success
Returns a pointer to the newly allocated duplicate string.
Failure
Returns NULL if memory allocation fails or if src is NULL.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Memory.c:120:
}
char *ZstrDupN(const char *src, size n) {
if (!src) {
LOG_FATAL("Invalid arguments");- In
Memory.c:140:
char *ZstrDup(const char *src) {
return ZstrDupN(src, ZstrLen(src));
}- In
Init.h:21:
# define StrInitFromCstr(cstr, len) \
(Str { \
.data = ZstrDupN((char *)(cstr), (len)), \
.length = (len), \
.capacity = (len), \- In
Init.h:48:
///
# define StrInitFromCstr(cstr, len) \
((Str) {.data = ZstrDupN((char *)(cstr), (len)), \
.length = (len), \
.capacity = (len), \
Last updated on