lib/string/sprintf/, lib/, src/, tests/: Move all sprintf(3)-like APIs to a subdirectory
And have a separate file for each pair of APIs. Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
committed by
Serge Hallyn
parent
89e4be3957
commit
22272347b6
+6
-4
@@ -144,12 +144,14 @@ libshadow_la_SOURCES = \
|
||||
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 \
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@
|
||||
#include "prototypes.h"
|
||||
#include "commonio.h"
|
||||
#include "shadowlog_internal.h"
|
||||
#include "string/sprintf.h"
|
||||
#include "string/sprintf/snprintf.h"
|
||||
|
||||
|
||||
/* local function prototypes */
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@
|
||||
#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;
|
||||
|
||||
@@ -20,7 +20,8 @@
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#include "shadowlog.h"
|
||||
#include "string/sprintf.h"
|
||||
#include "string/sprintf/snprintf.h"
|
||||
#include "string/sprintf/xasprintf.h"
|
||||
|
||||
|
||||
/*
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "atoi/getnum.h"
|
||||
#include "string/sprintf.h"
|
||||
#include "string/sprintf/snprintf.h"
|
||||
|
||||
|
||||
/*
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@
|
||||
#include "atoi/str2i.h"
|
||||
#include "getdef.h"
|
||||
#include "shadowlog_internal.h"
|
||||
#include "string/sprintf.h"
|
||||
#include "string/sprintf/xasprintf.h"
|
||||
|
||||
|
||||
/*
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@
|
||||
#include "defines.h"
|
||||
#include "prototypes.h"
|
||||
#include "getdef.h"
|
||||
#include "string/sprintf.h"
|
||||
#include "string/sprintf/snprintf.h"
|
||||
|
||||
|
||||
/*
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
#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>
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
|
||||
#include "alloc.h"
|
||||
#include "getdef.h"
|
||||
#include "string/sprintf.h"
|
||||
#include "string/sprintf/xasprintf.h"
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#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"
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@
|
||||
#endif /* ENABLE_SUBIDS */
|
||||
#include "getdef.h"
|
||||
#include "shadowlog.h"
|
||||
#include "string/sprintf.h"
|
||||
#include "string/sprintf/xasprintf.h"
|
||||
|
||||
|
||||
static char *passwd_db_file = NULL;
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@
|
||||
#include "prototypes.h"
|
||||
#include "pwauth.h"
|
||||
#include "getdef.h"
|
||||
#include "string/sprintf.h"
|
||||
#include "string/sprintf/snprintf.h"
|
||||
|
||||
#ifdef SKEY
|
||||
#include <skey.h>
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
#include <pwd.h>
|
||||
#include "getdef.h"
|
||||
#include "shadowlog.h"
|
||||
#include "string/sprintf.h"
|
||||
#include "string/sprintf/xasprintf.h"
|
||||
|
||||
|
||||
#ifndef USE_PAM
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
#include <errno.h>
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#include "string/sprintf.h"
|
||||
#include "string/sprintf/snprintf.h"
|
||||
|
||||
|
||||
extern char **newenvp;
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
* 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);
|
||||
@@ -0,0 +1,16 @@
|
||||
// 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);
|
||||
@@ -1,11 +1,9 @@
|
||||
/*
|
||||
* 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>
|
||||
@@ -15,19 +13,15 @@
|
||||
#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,
|
||||
...);
|
||||
@@ -36,35 +30,6 @@ inline int vsnprintf_(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, ...)
|
||||
{
|
||||
@@ -1,25 +1,17 @@
|
||||
/*
|
||||
* 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
|
||||
@@ -1,32 +1,27 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
|
||||
/*
|
||||
@@ -79,6 +74,7 @@ inline char *vstpeprintf(char *dst, char *end, const char *restrict fmt,
|
||||
*/
|
||||
|
||||
|
||||
#if !defined(HAVE_STPEPRINTF)
|
||||
inline char *
|
||||
stpeprintf(char *dst, char *end, const char *restrict fmt, ...)
|
||||
{
|
||||
@@ -91,8 +87,10 @@ 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)
|
||||
{
|
||||
@@ -114,7 +112,7 @@ vstpeprintf(char *dst, char *end, const char *restrict fmt, va_list ap)
|
||||
|
||||
return dst + len;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif // !HAVE_STPEPRINTF
|
||||
#endif // include guard
|
||||
@@ -0,0 +1,14 @@
|
||||
// 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);
|
||||
@@ -0,0 +1,54 @@
|
||||
// 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
|
||||
+1
-1
@@ -20,7 +20,7 @@
|
||||
|
||||
#include "alloc.h"
|
||||
#include "atoi/str2i.h"
|
||||
#include "string/sprintf.h"
|
||||
#include "string/sprintf/snprintf.h"
|
||||
|
||||
|
||||
#define ID_SIZE 31
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@
|
||||
#include "subordinateio.h"
|
||||
#endif /* ENABLE_SUBIDS */
|
||||
#include "shadowlog.h"
|
||||
#include "string/sprintf.h"
|
||||
#include "string/sprintf/snprintf.h"
|
||||
|
||||
|
||||
#ifdef __linux__
|
||||
|
||||
Reference in New Issue
Block a user