1
0
Fork 0

Adding upstream version 1:4.17.4.

Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
This commit is contained in:
Daniel Baumann 2025-06-22 05:06:56 +02:00
parent 8e3999c01a
commit 09a180ea01
Signed by: daniel.baumann
GPG key ID: BCC918A2ABD66424
11145 changed files with 938455 additions and 0 deletions

View file

@ -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);

View file

@ -0,0 +1,62 @@
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#ifndef SHADOW_INCLUDE_LIB_STRING_SPRINTF_SNPRINTF_H_
#define SHADOW_INCLUDE_LIB_STRING_SPRINTF_SNPRINTF_H_
#include <config.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include "attr.h"
#include "sizeof.h"
#define SNPRINTF(s, fmt, ...) \
( \
snprintf_(s, NITEMS(s), fmt __VA_OPT__(,) __VA_ARGS__) \
)
format_attr(printf, 3, 4)
inline int snprintf_(char *restrict s, size_t size, const char *restrict fmt,
...);
format_attr(printf, 3, 0)
inline int vsnprintf_(char *restrict s, size_t size, const char *restrict fmt,
va_list ap);
inline int
snprintf_(char *restrict s, size_t size, const char *restrict fmt, ...)
{
int len;
va_list ap;
va_start(ap, fmt);
len = vsnprintf_(s, size, fmt, ap);
va_end(ap);
return len;
}
inline int
vsnprintf_(char *restrict s, size_t size, const char *restrict fmt, va_list ap)
{
int len;
len = vsnprintf(s, size, fmt, ap);
if (len == -1)
return -1;
if ((size_t) len >= size)
return -1;
return len;
}
#endif // include guard

View file

@ -0,0 +1,17 @@
// SPDX-FileCopyrightText: 2022-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#include <config.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

View file

@ -0,0 +1,118 @@
// SPDX-FileCopyrightText: 2022-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#ifndef SHADOW_INCLUDE_LIB_STRING_SPRINTF_STPEPRINTF_H_
#define SHADOW_INCLUDE_LIB_STRING_SPRINTF_STPEPRINTF_H_
#include <config.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include "attr.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
/*
* SYNOPSIS
* [[gnu::format(printf, 3, 4)]]
* char *_Nullable stpeprintf(char *_Nullable dst, char end[0],
* const char *restrict fmt, ...);
*
* [[gnu::format(printf, 3, 0)]]
* char *_Nullable vstpeprintf(char *_Nullable dst, char end[0],
* const char *restrict fmt, va_list ap);
*
*
* ARGUMENTS
* dst Destination buffer where to write a string.
*
* end Pointer to one after the last element of the buffer
* pointed to by `dst`. Usually, it should be calculated
* as `dst + NITEMS(dst)`.
*
* fmt Format string
*
* ...
* ap Variadic argument list
*
* DESCRIPTION
* These functions are very similar to [v]snprintf(3).
*
* The destination buffer is limited by a pointer to its end --one
* after its last element-- instead of a size. This allows
* chaining calls to it safely, unlike [v]snprintf(3), which is
* difficult to chain without invoking Undefined Behavior.
*
* RETURN VALUE
* dst + strlen(dst)
* On success, these functions return a pointer to the
* terminating NUL byte.
*
* end
* If this call truncated the resulting string.
* If `dst == end` (a previous chained call to these
* functions truncated).
* NULL
* If this function failed (see ERRORS).
* If `dst == NULL` (a previous chained call to these
* functions failed).
*
* ERRORS
* These functions may fail for the same reasons as vsnprintf(3).
*/
#if !defined(HAVE_STPEPRINTF)
inline char *
stpeprintf(char *dst, char *end, const char *restrict fmt, ...)
{
char *p;
va_list ap;
va_start(ap, fmt);
p = vstpeprintf(dst, end, fmt, ap);
va_end(ap);
return p;
}
#endif
#if !defined(HAVE_STPEPRINTF)
inline char *
vstpeprintf(char *dst, char *end, const char *restrict fmt, va_list ap)
{
int len;
ptrdiff_t size;
if (dst == end)
return end;
if (dst == NULL)
return NULL;
size = end - dst;
len = vsnprintf(dst, size, fmt, ap);
if (len == -1)
return NULL;
if (len >= size)
return end;
return dst + len;
}
#endif
#endif // include guard

View file

@ -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);

View file

@ -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