This function is like strlcpy(3), but returns -1 on truncation, which makes it much easier to test. strlcpy(3) is useful in two cases: - We don't care if the output is truncated. strlcpy(3) is fine for those, and the return value can be ignored. - Truncation is bad. In that case, we just want to signal truncation, and the length of the original string is quite useless. Return the length iff no truncation so that we can use it if necessary. This simplifies the definition of the STRLCPY() macro. Signed-off-by: Alejandro Colomar <alx@kernel.org>
16 lines
276 B
C
16 lines
276 B
C
/*
|
|
* SPDX-FileCopyrightText: 2022-2023, Alejandro Colomar <alx@kernel.org>
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
*/
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#ident "$Id$"
|
|
|
|
#include "strlcpy.h"
|
|
|
|
|
|
extern inline size_t strlcpy_(char *restrict dst, const char *restrict src,
|
|
size_t size);
|