PatchworkOS
Loading...
Searching...
No Matches
vsnprintf.c
Go to the documentation of this file.
1
#include <
stdio.h
>
2
3
#include "
common/print.h
"
4
5
int
vsnprintf
(
char
*
_RESTRICT
s,
size_t
n,
const
char
*
_RESTRICT
format,
va_list
arg)
6
{
7
_format_ctx_t
ctx;
8
ctx.
base
= 0;
9
ctx.
flags
= 0;
10
ctx.
maxChars
= n;
11
ctx.
totalChars
= 0;
12
ctx.
currentChars
= 0;
13
ctx.
buffer
= s;
14
ctx.
width
= 0;
15
ctx.
precision
=
EOF
;
16
ctx.
stream
=
NULL
;
17
va_copy
(ctx.
arg
, arg);
18
19
while
(*format !=
'\0'
)
20
{
21
const
char
* rc;
22
23
if
((*format !=
'%'
) || ((rc =
_print
(format, &ctx)) == format))
24
{
25
if
(ctx.
totalChars
< n)
26
{
27
s[ctx.
totalChars
] = *format;
28
}
29
30
ctx.
totalChars
++;
31
format++;
32
}
33
else
34
{
35
/* Continue parsing after conversion specifier */
36
format = rc;
37
}
38
}
39
40
if
(ctx.
totalChars
< n)
41
{
42
s[ctx.
totalChars
] =
'\0'
;
43
}
44
45
va_end
(ctx.
arg
);
46
return
ctx.
totalChars
;
47
}
NULL
#define NULL
Pointer error value.
Definition
NULL.h:23
_RESTRICT
#define _RESTRICT
Definition
config.h:17
_print
const char * _print(const char *spec, _format_ctx_t *ctx)
Definition
print.c:561
print.h
va_copy
#define va_copy(dest, src)
Definition
stdarg.h:12
va_end
#define va_end(ap)
Definition
stdarg.h:13
va_list
__builtin_va_list va_list
Definition
stdarg.h:9
stdio.h
EOF
#define EOF
Definition
stdio.h:25
_format_ctx_t
Definition
format.h:35
_format_ctx_t::arg
va_list arg
Definition
format.h:45
_format_ctx_t::precision
int64_t precision
Definition
format.h:43
_format_ctx_t::stream
FILE * stream
Definition
format.h:44
_format_ctx_t::maxChars
uint64_t maxChars
Definition
format.h:38
_format_ctx_t::width
uint64_t width
Definition
format.h:42
_format_ctx_t::flags
_format_flags_t flags
Definition
format.h:37
_format_ctx_t::base
int32_t base
Definition
format.h:36
_format_ctx_t::currentChars
uint64_t currentChars
Definition
format.h:40
_format_ctx_t::buffer
char * buffer
Definition
format.h:41
_format_ctx_t::totalChars
uint64_t totalChars
Definition
format.h:39
vsnprintf
int vsnprintf(char *_RESTRICT s, size_t n, const char *_RESTRICT format, va_list arg)
Definition
vsnprintf.c:5
src
libstd
functions
stdio
vsnprintf.c
Generated by
1.9.8