And have a separate file for each pair of APIs.
Signed-off-by: Alejandro Colomar <alx@kernel.org>
spawn.c \
sssd.c \
sssd.h \
- string/sprintf.c \
- string/sprintf.h \
+ string/sprintf/snprintf.c \
+ string/sprintf/snprintf.h \
+ string/sprintf/stpeprintf.c \
+ string/sprintf/stpeprintf.h \
+ string/sprintf/xasprintf.c \
+ string/sprintf/xasprintf.h \
string/stpecpy.c \
string/stpecpy.h \
- string/stpeprintf.c \
- string/stpeprintf.h \
string/strftime.c \
string/strftime.h \
string/strncpy.h \
#include "prototypes.h"
#include "commonio.h"
#include "shadowlog_internal.h"
-#include "string/sprintf.h"
+#include "string/sprintf/snprintf.h"
/* local function prototypes */
#include <attr/libattr.h>
#endif /* WITH_ATTR */
#include "shadowlog.h"
-#include "string/sprintf.h"
+#include "string/sprintf/xasprintf.h"
static /*@null@*/const char *src_orig;
#include "prototypes.h"
#include "defines.h"
#include "shadowlog.h"
-#include "string/sprintf.h"
+#include "string/sprintf/snprintf.h"
+#include "string/sprintf/xasprintf.h"
/*
#include <fcntl.h>
#include "atoi/getnum.h"
-#include "string/sprintf.h"
+#include "string/sprintf/snprintf.h"
/*
#include "atoi/str2i.h"
#include "getdef.h"
#include "shadowlog_internal.h"
-#include "string/sprintf.h"
+#include "string/sprintf/xasprintf.h"
/*
#include "defines.h"
#include "prototypes.h"
#include "getdef.h"
-#include "string/sprintf.h"
+#include "string/sprintf/snprintf.h"
/*
#include "alloc.h"
#include "atoi/str2i.h"
#include "prototypes.h"
-#include "string/stpeprintf.h"
+#include "string/sprintf/stpeprintf.h"
#include "idmapping.h"
#if HAVE_SYS_CAPABILITY_H
#include <sys/prctl.h>
#include "alloc.h"
#include "getdef.h"
-#include "string/sprintf.h"
+#include "string/sprintf/xasprintf.h"
#ident "$Id$"
#include "../libsubid/subid.h"
#include "shadowlog_internal.h"
#include "shadowlog.h"
-#include "string/sprintf.h"
+#include "string/sprintf/snprintf.h"
#define NSSWITCH "/etc/nsswitch.conf"
#endif /* ENABLE_SUBIDS */
#include "getdef.h"
#include "shadowlog.h"
-#include "string/sprintf.h"
+#include "string/sprintf/xasprintf.h"
static char *passwd_db_file = NULL;
#include "prototypes.h"
#include "pwauth.h"
#include "getdef.h"
-#include "string/sprintf.h"
+#include "string/sprintf/snprintf.h"
#ifdef SKEY
#include <skey.h>
#include <pwd.h>
#include "getdef.h"
#include "shadowlog.h"
-#include "string/sprintf.h"
+#include "string/sprintf/xasprintf.h"
#ifndef USE_PAM
#include <errno.h>
#include "prototypes.h"
#include "defines.h"
-#include "string/sprintf.h"
+#include "string/sprintf/snprintf.h"
extern char **newenvp;
+++ /dev/null
-/*
- * SPDX-FileCopyrightText: 2023, Alejandro Colomar <alx@kernel.org>
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#include <config.h>
-
-#ident "$Id$"
-
-#include "string/sprintf.h"
-
-#include <stdarg.h>
-#include <stddef.h>
-#include <stdio.h>
-
-
-extern inline int xasprintf(char **restrict s, const char *restrict fmt, ...);
-extern inline int xvasprintf(char **restrict s, const char *restrict fmt,
- va_list ap);
-
-extern inline int snprintf_(char *restrict s, size_t size,
- const char *restrict fmt, ...);
-extern inline int vsnprintf_(char *restrict s, size_t size,
- const char *restrict fmt, va_list ap);
--- /dev/null
+// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#include <config.h>
+
+#include "string/sprintf/snprintf.h"
+
+#include <stdarg.h>
+#include <stddef.h>
+
+
+extern inline int snprintf_(char *restrict s, size_t size,
+ const char *restrict fmt, ...);
+extern inline int vsnprintf_(char *restrict s, size_t size,
+ const char *restrict fmt, va_list ap);
-/*
- * SPDX-FileCopyrightText: 2023, Alejandro Colomar <alx@kernel.org>
- * SPDX-License-Identifier: BSD-3-Clause
- */
+// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
-#ifndef SHADOW_INCLUDE_LIB_SPRINTF_H_
-#define SHADOW_INCLUDE_LIB_SPRINTF_H_
+#ifndef SHADOW_INCLUDE_LIB_STRING_SPRINTF_SNPRINTF_H_
+#define SHADOW_INCLUDE_LIB_STRING_SPRINTF_SNPRINTF_H_
#include <config.h>
#include <stdio.h>
#include "attr.h"
-#include "defines.h"
#include "sizeof.h"
#define SNPRINTF(s, fmt, ...) \
- snprintf_(s, NITEMS(s), fmt __VA_OPT__(,) __VA_ARGS__)
+( \
+ snprintf_(s, NITEMS(s), fmt __VA_OPT__(,) __VA_ARGS__) \
+)
-format_attr(printf, 2, 3)
-inline int xasprintf(char **restrict s, const char *restrict fmt, ...);
-format_attr(printf, 2, 0)
-inline int xvasprintf(char **restrict s, const char *restrict fmt, va_list ap);
-
format_attr(printf, 3, 4)
inline int snprintf_(char *restrict s, size_t size, const char *restrict fmt,
...);
va_list ap);
-inline int
-xasprintf(char **restrict s, const char *restrict fmt, ...)
-{
- int len;
- va_list ap;
-
- va_start(ap, fmt);
- len = xvasprintf(s, fmt, ap);
- va_end(ap);
-
- return len;
-}
-
-
-inline int
-xvasprintf(char **restrict s, const char *restrict fmt, va_list ap)
-{
- int len;
-
- len = vasprintf(s, fmt, ap);
- if (len == -1) {
- perror("asprintf");
- exit(EXIT_FAILURE);
- }
-
- return len;
-}
-
-
inline int
snprintf_(char *restrict s, size_t size, const char *restrict fmt, ...)
{
-/*
- * SPDX-FileCopyrightText: 2022 - 2023, Alejandro Colomar <alx@kernel.org>
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
+// SPDX-FileCopyrightText: 2022-2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
#include <config.h>
-#if !defined(HAVE_STPEPRINTF)
-
-#ident "$Id$"
-
-#include "string/stpeprintf.h"
+#include "string/sprintf/stpeprintf.h"
#include <stdarg.h>
+#if !defined(HAVE_STPEPRINTF)
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
+#endif
-/*
- * SPDX-FileCopyrightText: 2022 - 2023, Alejandro Colomar <alx@kernel.org>
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
+// SPDX-FileCopyrightText: 2022-2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
-#ifndef SHADOW_INCLUDE_LIB_STPEPRINTF_H_
-#define SHADOW_INCLUDE_LIB_STPEPRINTF_H_
+#ifndef SHADOW_INCLUDE_LIB_STRING_SPRINTF_STPEPRINTF_H_
+#define SHADOW_INCLUDE_LIB_STRING_SPRINTF_STPEPRINTF_H_
#include <config.h>
-#if !defined(HAVE_STPEPRINTF)
-
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include "attr.h"
-#include "defines.h"
+#if !defined(HAVE_STPEPRINTF)
format_attr(printf, 3, 4)
inline char *stpeprintf(char *dst, char *end, const char *restrict fmt, ...);
-
format_attr(printf, 3, 0)
inline char *vstpeprintf(char *dst, char *end, const char *restrict fmt,
va_list ap);
+#endif
/*
*/
+#if !defined(HAVE_STPEPRINTF)
inline char *
stpeprintf(char *dst, char *end, const char *restrict fmt, ...)
{
return p;
}
+#endif
+#if !defined(HAVE_STPEPRINTF)
inline char *
vstpeprintf(char *dst, char *end, const char *restrict fmt, va_list ap)
{
return dst + len;
}
+#endif
-#endif // !HAVE_STPEPRINTF
#endif // include guard
--- /dev/null
+// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#include <config.h>
+
+#include "string/sprintf/xasprintf.h"
+
+#include <stdarg.h>
+
+
+extern inline int xasprintf(char **restrict s, const char *restrict fmt, ...);
+extern inline int xvasprintf(char **restrict s, const char *restrict fmt,
+ va_list ap);
--- /dev/null
+// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#ifndef SHADOW_INCLUDE_LIB_STRING_SPRINTF_XASPRINTF_H_
+#define SHADOW_INCLUDE_LIB_STRING_SPRINTF_XASPRINTF_H_
+
+
+#include <config.h>
+
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "attr.h"
+
+
+format_attr(printf, 2, 3)
+inline int xasprintf(char **restrict s, const char *restrict fmt, ...);
+format_attr(printf, 2, 0)
+inline int xvasprintf(char **restrict s, const char *restrict fmt, va_list ap);
+
+
+inline int
+xasprintf(char **restrict s, const char *restrict fmt, ...)
+{
+ int len;
+ va_list ap;
+
+ va_start(ap, fmt);
+ len = xvasprintf(s, fmt, ap);
+ va_end(ap);
+
+ return len;
+}
+
+
+inline int
+xvasprintf(char **restrict s, const char *restrict fmt, va_list ap)
+{
+ int len;
+
+ len = vasprintf(s, fmt, ap);
+ if (len == -1) {
+ perror("asprintf");
+ exit(EXIT_FAILURE);
+ }
+
+ return len;
+}
+
+
+#endif // include guard
#include "alloc.h"
#include "atoi/str2i.h"
-#include "string/sprintf.h"
+#include "string/sprintf/snprintf.h"
#define ID_SIZE 31
#include "subordinateio.h"
#endif /* ENABLE_SUBIDS */
#include "shadowlog.h"
-#include "string/sprintf.h"
+#include "string/sprintf/snprintf.h"
#ifdef __linux__
#include "pwio.h"
#include "shadowio.h"
#include "shadowlog.h"
-#include "string/sprintf.h"
+#include "string/sprintf/snprintf.h"
#include "string/strftime.h"
#include "string/strtcpy.h"
#include "time/day_to_str.h"
/*@-exitarg@*/
#include "exitcodes.h"
#include "shadowlog.h"
-#include "string/sprintf.h"
+#include "string/sprintf/snprintf.h"
#include "string/strtcpy.h"
/*@-exitarg@*/
#include "exitcodes.h"
#include "shadowlog.h"
-#include "string/sprintf.h"
+#include "string/sprintf/snprintf.h"
#include "string/strtcpy.h"
#include "sgroupio.h"
#endif
#include "shadowlog.h"
+#include "string/sprintf/stpeprintf.h"
#include "string/stpecpy.h"
-#include "string/stpeprintf.h"
/*
/*@-exitarg@*/
#include "exitcodes.h"
#include "shadowlog.h"
-#include "string/sprintf.h"
+#include "string/sprintf/snprintf.h"
#include "string/strftime.h"
#include "string/strtcpy.h"
/*@-exitarg@*/
#include "exitcodes.h"
#include "shadowlog.h"
-#include "string/sprintf.h"
+#include "string/sprintf/snprintf.h"
/*
#endif /* ENABLE_SUBIDS */
#include "chkname.h"
#include "shadowlog.h"
-#include "string/sprintf.h"
+#include "string/sprintf/snprintf.h"
/*
/*@-exitarg@*/
#include "exitcodes.h"
#include "shadowlog.h"
-#include "string/sprintf.h"
+#include "string/sprintf/snprintf.h"
#include "string/strtcpy.h"
#include "tcbfuncs.h"
#endif
#include "shadowlog.h"
-#include "string/sprintf.h"
+#include "string/sprintf/snprintf.h"
+#include "string/sprintf/xasprintf.h"
#ifndef SKEL_DIR
#include "subordinateio.h"
#endif /* ENABLE_SUBIDS */
#include "shadowlog.h"
-#include "string/sprintf.h"
+#include "string/sprintf/xasprintf.h"
/*
#include "tcbfuncs.h"
#endif
#include "shadowlog.h"
-#include "string/sprintf.h"
+#include "string/sprintf/xasprintf.h"
#include "time/day_to_str.h"
#include "tcbfuncs.h"
#endif /* WITH_TCB */
#include "shadowlog.h"
-#include "string/sprintf.h"
+#include "string/sprintf/snprintf.h"
+#include "string/sprintf/xasprintf.h"
#define MSG_WARN_EDIT_OTHER_FILE _( \
test_adds \
test_atoi_strtoi \
test_chkname \
- test_sprintf \
+ test_snprintf \
test_strncpy \
test_strtcpy \
test_typetraits \
$(LIBSYSTEMD) \
$(NULL)
-test_sprintf_SOURCES = \
- ../../lib/string/sprintf.c \
- test_sprintf.c \
+test_snprintf_SOURCES = \
+ ../../lib/string/sprintf/snprintf.c \
+ test_snprintf.c \
$(NULL)
-test_sprintf_CFLAGS = \
+test_snprintf_CFLAGS = \
$(AM_CFLAGS) \
$(NULL)
-test_sprintf_LDFLAGS = \
+test_snprintf_LDFLAGS = \
$(NULL)
-test_sprintf_LDADD = \
+test_snprintf_LDADD = \
$(CMOCKA_LIBS) \
$(NULL)
$(NULL)
test_xasprintf_SOURCES = \
- ../../lib/string/sprintf.c \
+ ../../lib/string/sprintf/xasprintf.c \
test_xasprintf.c \
$(NULL)
test_xasprintf_CFLAGS = \
#include <cmocka.h>
#include "sizeof.h"
-#include "string/sprintf.h"
+#include "string/sprintf/snprintf.h"
static void test_SNPRINTF_trunc(void **state);
#include <stdint.h> // Required by <cmocka.h>
#include <cmocka.h>
-#include "string/sprintf.h"
+#include "string/sprintf/xasprintf.h"
#define assert_unreachable() assert_true(0)