🧵 str
Painfully common string utilities for C
Toggle main menu visibility
Loading...
Searching...
No Matches
cstr.h
Go to the documentation of this file.
1
/*
2
* 🧵 str — cstr.h
3
* Copyright (c) 2025–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
21
#pragma once
22
#include <stddef.h>
23
24
#if __STDC_VERSION__ < 202311L && (!defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE < 200809L)
25
26
// MSVC has memccpy() and strdup(), though it will complain about using
27
// the POSIX names `memccpy()` & `strdup()` rather than the
28
// MSVC-specific `_memccpy()` & `_strdup()`.
29
// https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/memccpy
30
// https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/strdup-wcsdup-mbsdup
31
#if !defined(NO_STR_MEMCCPY) && !defined(_MSC_VER)
32
46
void
*
memccpy
(
void
*restrict dest,
const
void
*restrict src,
int
ch,
size_t
len);
47
58
char
*
strdup
(
const
char
*src);
59
60
#endif
61
76
char
*
strndup
(
const
char
*src,
size_t
size);
77
78
#endif
79
132
char
*
strzcpy
(
char
dest[restrict
static
1],
const
char
src[restrict
static
1],
size_t
len);
strzcpy
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.
memccpy
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.
strdup
char * strdup(const char *src)
Duplicates a nil-terminated string.
strndup
char * strndup(const char *src, size_t size)
Duplicates a nil-terminated string, up to a maximum length.
cstr.h
Generated by
1.17.0