New upstream version 4.18.0
This commit is contained in:
13
lib/string/sprintf/aprintf.c
Normal file
13
lib/string/sprintf/aprintf.c
Normal file
@@ -0,0 +1,13 @@
|
||||
// SPDX-FileCopyrightText: 2025, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "string/sprintf/aprintf.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
extern inline char *aprintf(const char *restrict fmt, ...);
|
||||
extern inline char *vaprintf(const char *restrict fmt, va_list ap);
|
||||
57
lib/string/sprintf/aprintf.h
Normal file
57
lib/string/sprintf/aprintf.h
Normal file
@@ -0,0 +1,57 @@
|
||||
// SPDX-FileCopyrightText: 2025, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_STRING_SPRINTF_APRINTF_H_
|
||||
#define SHADOW_INCLUDE_LIB_STRING_SPRINTF_APRINTF_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
ATTR_MALLOC(free)
|
||||
format_attr(printf, 1, 2)
|
||||
inline char *aprintf(const char *restrict fmt, ...);
|
||||
|
||||
ATTR_MALLOC(free)
|
||||
format_attr(printf, 1, 0)
|
||||
inline char *vaprintf(const char *restrict fmt, va_list ap);
|
||||
|
||||
|
||||
// allocate print formatted
|
||||
// Like asprintf(3), but simpler; omit the length.
|
||||
inline char *
|
||||
aprintf(const char *restrict fmt, ...)
|
||||
{
|
||||
char *p;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
p = vaprintf(fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
// Like vasprintf(3), but simpler; omit the length.
|
||||
inline char *
|
||||
vaprintf(const char *restrict fmt, va_list ap)
|
||||
{
|
||||
char *p;
|
||||
|
||||
if (vasprintf(&p, fmt, ap) == -1)
|
||||
return NULL;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
#define SNPRINTF(s, fmt, ...) \
|
||||
( \
|
||||
snprintf_(s, NITEMS(s), fmt __VA_OPT__(,) __VA_ARGS__) \
|
||||
snprintf_(s, countof(s), fmt __VA_OPT__(,) __VA_ARGS__) \
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ inline char *vstpeprintf(char *dst, char *end, const char *restrict fmt,
|
||||
*
|
||||
* end Pointer to one after the last element of the buffer
|
||||
* pointed to by `dst`. Usually, it should be calculated
|
||||
* as `dst + NITEMS(dst)`.
|
||||
* as `dst + countof(dst)`.
|
||||
*
|
||||
* fmt Format string
|
||||
*
|
||||
|
||||
13
lib/string/sprintf/xaprintf.c
Normal file
13
lib/string/sprintf/xaprintf.c
Normal file
@@ -0,0 +1,13 @@
|
||||
// SPDX-FileCopyrightText: 2023-2025, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "string/sprintf/xaprintf.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
extern inline char *xaprintf(const char *restrict fmt, ...);
|
||||
extern inline char *xvaprintf(const char *restrict fmt, va_list ap);
|
||||
59
lib/string/sprintf/xaprintf.h
Normal file
59
lib/string/sprintf/xaprintf.h
Normal file
@@ -0,0 +1,59 @@
|
||||
// SPDX-FileCopyrightText: 2023-2025, 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"
|
||||
#include "string/sprintf/aprintf.h"
|
||||
|
||||
|
||||
ATTR_MALLOC(free)
|
||||
format_attr(printf, 1, 2)
|
||||
inline char *xaprintf(const char *restrict fmt, ...);
|
||||
|
||||
ATTR_MALLOC(free)
|
||||
format_attr(printf, 1, 0)
|
||||
inline char *xvaprintf(const char *restrict fmt, va_list ap);
|
||||
|
||||
|
||||
// exit-on-error allocate print formatted
|
||||
inline char *
|
||||
xaprintf(const char *restrict fmt, ...)
|
||||
{
|
||||
char *p;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
p = xvaprintf(fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
inline char *
|
||||
xvaprintf(const char *restrict fmt, va_list ap)
|
||||
{
|
||||
char *p;
|
||||
|
||||
p = vaprintf(fmt, ap);
|
||||
if (p == NULL) {
|
||||
perror("vaprintf");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
@@ -1,14 +0,0 @@
|
||||
// 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);
|
||||
@@ -1,54 +0,0 @@
|
||||
// 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
|
||||
Reference in New Issue
Block a user