Files
shadow/lib/string/strdup/strndupa.h
2026-01-06 00:37:15 +01:00

28 lines
607 B
C

// SPDX-FileCopyrightText: 2024-2025, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#ifndef SHADOW_INCLUDE_LIB_STRING_STRDUP_STRNDUPA_H_
#define SHADOW_INCLUDE_LIB_STRING_STRDUP_STRNDUPA_H_
#include "config.h"
#include <alloca.h>
#include <string.h>
#include "sizeof.h"
// strndupa - nonstring duplicate-into-string using-alloca(3)
#ifndef strndupa
# define strndupa(s, n) strncat(strcpy(alloca(n + 1), ""), s, n)
#endif
// strndupa_a - nonstring duplicate-into-string using-alloca(3) array
#define strndupa_a(s) strndupa(s, countof(s))
#endif // include guard