🧵 str
Painfully common string utilities for C
Loading...
Searching...
No Matches
cstr.h
Go to the documentation of this file.
1/*
2 * 🧵 str — cstr.h
3 * Copyright (c) 2026 Fawn <rubiefawn@gmail.com>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
19#pragma once
20#include <stddef.h>
21
29ptrdiff_t strzcpy(char *restrict dest, const char *restrict src, size_t size);
30
38ptrdiff_t strzcat(char *restrict dest, const char *restrict src, size_t size);
39
40#if __STDC_VERSION__ < 202311L && (!defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE < 200809L)
41
48char *strdup(const char *src);
49
60char *strndup(const char *src, size_t size);
61
62#endif
ptrdiff_t strzcpy(char *restrict dest, const char *restrict src, size_t size)
Similar to strncpy(), except result is always null-terminated.
Definition cstr.c:21
char * strdup(const char *src)
Duplicates a null-terminated string.
Definition cstr.c:37
ptrdiff_t strzcat(char *restrict dest, const char *restrict src, size_t size)
Similar to strncat(), except result is always null-terminated.
Definition cstr.c:29
char * strndup(const char *src, size_t size)
Duplicates a null-terminated string, up to a maximum length.
Definition cstr.c:45