Add stpeprintf()
[v]stpeprintf() are similar to [v]snprintf(3), but they allow chaining. [v]snprintf(3) are very dangerous for catenating strings, since the obvious ways to do it invoke Undefined Behavior, and the ways that avoid UB are very error-prone. Cc: Iker Pedrosa <ipedrosa@redhat.com> Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
committed by
Iker Pedrosa
parent
a187ad8e9e
commit
7e213cfb50
25
libmisc/stpeprintf.c
Normal file
25
libmisc/stpeprintf.c
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022 - 2023, Alejandro Colomar <alx@kernel.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#if !defined(HAVE_STPEPRINTF)
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
#include "stpeprintf.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
extern inline char *stpeprintf(char *dst, char *end, const char *restrict fmt,
|
||||
...);
|
||||
extern inline char *vstpeprintf(char *dst, char *end, const char *restrict fmt,
|
||||
va_list ap);
|
||||
|
||||
|
||||
#endif // !HAVE_STPEPRINTF
|
Reference in New Issue
Block a user