XenevaOS
Loading...
Searching...
No Matches
sprintf.h
Go to the documentation of this file.
1#ifndef __LINUX_SPRINTF_H
2#define __LINUX_SPRINTF_H
3
4/* _vsnprintf lives in Xeneva's own header rather than being restated here:
5 * _print.c is what implements it, and <Log/_print.h> also pulls <stdarg.h>
6 * for the va_list the declaration needs. sprintf.h's own note about being
7 * va_list-free (see below) describes the *macros* in this file, not this
8 * declaration. */
9#include <Log/_print.h>
10
11/*
12 * DCL <linux/sprintf.h> -- sprintf() and friends.
13 *
14 * mainline has this as a header of its own and reaches it from
15 * <linux/kernel.h> (`#include <linux/sprintf.h>`), which is why a ported
16 * source never names it: virtio-rng.c:165 writes
17 *
18 * sprintf(vi->name, "virtio_rng.%d", index);
19 *
20 * while including only its own driver headers. Left undeclared the call is
21 * implicitly `int sprintf()`, and because sprintf's real return type *is*
22 * int the result links cleanly -- the compiler has assumed int for every
23 * argument too, so a wrong pointer type at a future call site would be
24 * accepted rather than caught. The declaration exists so the arguments are
25 * checked against something.
26 *
27 * DCL maps sprintf() onto Xeneva's _sprintf() rather than providing a body.
28 *
29 * KernelAA64/Log/_print.c:827 is
30 *
31 * int _sprintf(char* output, const char* format, ...);
32 *
33 * -- identical in shape to mainline's `int sprintf(char *buf, const char
34 * *fmt, ...)` -- and it is already in the image, already exported to loaded
35 * modules through KernelAA64/kernel_exports.c (which is how the prebuilt
36 * virtio_rng.ko reached it). A wrapper would be a second copy of the same
37 * call with a va_list hand-rolled around it, buying only the name. The name
38 * is what this header is for.
39 *
40 * A macro rather than a static inline: the compiler sees one declaration
41 * with the real signature and checks the call site against it, and no
42 * forwarding function has to redeclare the varargs itself.
43 *
44 * Worth knowing before a ported file leans on it: _sprintf runs through a
45 * fixed 192-byte va_list scratch buffer and a MAX_STRING_LENGTH output cap
46 * in _print.c. It is a boot-time debug formatter that happens to be correct
47 * for the short strings drivers use to name devices -- it bounds the output
48 * by MAX_STRING_LENGTH, not by the size of the caller's buffer.
49 *
50 * snprintf() is here now, because sysfs_emit() asked for it (the first ported
51 * file to need a *bounded* format: rx_trig_bytes_show writes "%d\n" into a
52 * page-sized sysfs buffer). Xeneva already had the body -- _snprintf(output,
53 * sz, format, ...) in <Log/_print.h>, same shape as mainline's, bound by both
54 * the caller's size and _print.c's MAX_STRING_LENGTH -- so this is a
55 * declaration and a spelling, with no new formatter behind it. vsnprintf and
56 * vscnprintf are still absent: no caller yet, and each would need
57 * <linux/stdarg.h> plumbing that the one user did not. vsnprintf is here
58 * now, because seq_buf.c:74 needs it: `len = vsnprintf(s->buffer + s->len,
59 * s->size - s->len, fmt, args);` is a *bounded* format into a caller-owned
60 * buffer, which is exactly what <Log/_print.h>'s _vsnprintf already does --
61 * the two signatures are the same three arguments plus a va_list, in the same
62 * order, so this is the same decision as snprintf() above: a spelling, with
63 * no second formatter behind it. vscnprintf is still absent, which is
64 * consistent -- nothing has asked for it.
65 */
66extern int _sprintf(char* output, const char* format, ...);
67#define sprintf _sprintf
68
69
70extern int _snprintf(char* output, size_t sz, const char* format, ...);
71#define snprintf _snprintf
72
73/*
74 * A macro rather than a static inline, for the same reason the comment at the
75 * top gives for sprintf(): the compiler checks the call site against
76 * _vsnprintf's real signature, and no forwarding function has to restate the
77 * va_list parameter.
78 */
79#define vsnprintf _vsnprintf
80#endif /* __LINUX_SPRINTF_H */
const char const char * format
Definition drm_print.h:516
void _sprintf(void)
int _snprintf(char *output, size_t sz, const char *format,...)
Definition _print.c:838