/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _LINUX_KERNEL_SPRINTF_H_
#define _LINUX_KERNEL_SPRINTF_H_
#include <linux/compiler_attributes.h>
#include <linux/types.h>
#include <linux/stdarg.h>
int num_to_str(char *buf, int size, unsigned long long num, unsigned int width);
__printf(2, 3) int sprintf(char *buf, const char * fmt, ...);
__printf(2, 0) int vsprintf(char *buf, const char *, va_list);
__printf(3, 4) int snprintf(char *buf, size_t size, const char *fmt, ...);
__printf(3, 0) int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
__printf(3, 4) int scnprintf(char *buf, size_t size, const char *fmt, ...);
__printf(3, 0) int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
#define _kvasprintf(gfp, fmt, ap) \
({ \
unsigned int __as_first; \
char *__as_p; \
va_list __as_aq; \
\
va_copy(__as_aq, ap); \
__as_first = vsnprintf(NULL, 0, fmt, __as_aq); \
va_end(__as_aq); \
\
__as_p = kmalloc(__as_first+1, gfp); \
__as_p ? __kvasprintf(__as_p, __as_first, fmt, ap) : __as_p; \
})
#define _kvasprintf_const(gfp, fmt, ap) \
({ \
const char *__as_p; \
\
if (!strcmp(fmt, "%s")) \
__as_p = kstrdup_const(va_arg(ap, const char*), gfp); \
else if (!strchr(fmt, '%')) \
__as_p = kstrdup_const(fmt, gfp); \
else \
__as_p = kvasprintf(gfp, fmt, ap); \
__as_p; \
})
#ifdef AUTOSLAB_PLUGIN
//extern __printf(3, 0)
char *__kvasprintf(char *p, unsigned int first, const char *fmt, va_list ap);
#define kvasprintf _kvasprintf
#define kvasprintf_const _kvasprintf_const
/* !!! keep in sync with the master copy in include/linux/slab.h !!! */
void *kmalloc(size_t size, gfp_t flags)
/*__assume_kmalloc_alignment*/ __malloc __alloc_size(1) __alloc_gfp_flags(2);
/* this is never defined as all calls to it will be converted by AUTOSLAB */
void *kmalloc_typename(size_t size, gfp_t flags, const char *typename)
/*__assume_kmalloc_alignment*/ __malloc __alloc_size(1) __alloc_gfp_flags(2);
static inline __printf(2, 3) __malloc __alloc_gfp_flags(1)
char *kasprintf(gfp_t gfp, const char *fmt, ...)
{
va_list ap;
char *p;
va_start(ap, fmt);
p = kvasprintf(gfp, fmt, ap);
va_end(ap);
return p;
}
#else
__printf(2, 3) __malloc __alloc_gfp_flags(1)
char *kasprintf(gfp_t gfp, const char *fmt, ...);
__printf(2, 0) __malloc __alloc_gfp_flags(1)
char *kvasprintf(gfp_t gfp, const char *fmt, va_list args);
__printf(2, 0) __malloc __alloc_gfp_flags(1)
const char *kvasprintf_const(gfp_t gfp, const char *fmt, va_list args);
#endif
__scanf(2, 3) int sscanf(const char *, const char *, ...);
__scanf(2, 0) int vsscanf(const char *, const char *, va_list);
/* These are for specific cases, do not use without real need */
extern const bool no_hash_pointers;
int no_hash_pointers_enable(char *str);
#endif /* _LINUX_KERNEL_SPRINTF_H */