shadow/lib/string/sprintf.h
Alejandro Colomar dbb37b1b31 lib/string/: Move string-related files to string/ subdir
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-03 12:22:11 -06:00

57 lines
940 B
C

/*
* SPDX-FileCopyrightText: 2023, Alejandro Colomar <alx@kernel.org>
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef SHADOW_INCLUDE_LIB_SPRINTF_H_
#define SHADOW_INCLUDE_LIB_SPRINTF_H_
#include <config.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include "attr.h"
#include "defines.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