xref: /aosp_15_r20/trusty/kernel/lib/libc-ext/include/trusty/string.h (revision 344aa361028b423587d4ef3fa52a23d194628137)
1*344aa361SAndroid Build Coastguard Worker #pragma once
2*344aa361SAndroid Build Coastguard Worker 
3*344aa361SAndroid Build Coastguard Worker #include <lk/compiler.h>
4*344aa361SAndroid Build Coastguard Worker #include <stdarg.h>
5*344aa361SAndroid Build Coastguard Worker #include <stddef.h>
6*344aa361SAndroid Build Coastguard Worker 
7*344aa361SAndroid Build Coastguard Worker __BEGIN_CDECLS
8*344aa361SAndroid Build Coastguard Worker 
9*344aa361SAndroid Build Coastguard Worker /*
10*344aa361SAndroid Build Coastguard Worker  * scnprintf/vscnprintf is like snprintf/vsnprintf, but returns the number of
11*344aa361SAndroid Build Coastguard Worker  * characters actually written to the buffer rather than the number it would
12*344aa361SAndroid Build Coastguard Worker  * write if given arbitrary space.
13*344aa361SAndroid Build Coastguard Worker  */
14*344aa361SAndroid Build Coastguard Worker 
15*344aa361SAndroid Build Coastguard Worker /**
16*344aa361SAndroid Build Coastguard Worker  * scnprintf()
17*344aa361SAndroid Build Coastguard Worker  * @buf - output buffer
18*344aa361SAndroid Build Coastguard Worker  * @size - amount of space available in the output buffer
19*344aa361SAndroid Build Coastguard Worker  * @fmt - printf-style format string
20*344aa361SAndroid Build Coastguard Worker  * @... - arguments to format in the format string
21*344aa361SAndroid Build Coastguard Worker  *
22*344aa361SAndroid Build Coastguard Worker  * scnprintf() is like snprintf(), but returns the amount of space it used in
23*344aa361SAndroid Build Coastguard Worker  * the buffer rather than how large the formatted string would be.
24*344aa361SAndroid Build Coastguard Worker  *
25*344aa361SAndroid Build Coastguard Worker  * Specifically, scnprintf will use printf semantics to expand @fmt with @...,
26*344aa361SAndroid Build Coastguard Worker  * writing the first @size characters to the buffer.
27*344aa361SAndroid Build Coastguard Worker  *
28*344aa361SAndroid Build Coastguard Worker  * Return: The number of characters written to the buffer.
29*344aa361SAndroid Build Coastguard Worker  */
30*344aa361SAndroid Build Coastguard Worker __attribute__((__format__ (__printf__, 3, 4))) /* */
31*344aa361SAndroid Build Coastguard Worker int scnprintf(char* buf, size_t size, const char* fmt, ...);
32*344aa361SAndroid Build Coastguard Worker 
33*344aa361SAndroid Build Coastguard Worker /**
34*344aa361SAndroid Build Coastguard Worker  * vscnprintf()
35*344aa361SAndroid Build Coastguard Worker  * @buf - output buffer
36*344aa361SAndroid Build Coastguard Worker  * @size - amount of space available in the output buffer
37*344aa361SAndroid Build Coastguard Worker  * @fmt - printf-style format string
38*344aa361SAndroid Build Coastguard Worker  * @args - arguments to format in the format string
39*344aa361SAndroid Build Coastguard Worker  *
40*344aa361SAndroid Build Coastguard Worker  * vscnprintf() is like vsnprintf(), but returns the amount of space it used in
41*344aa361SAndroid Build Coastguard Worker  * the buffer rather than how large the formatted string would be.
42*344aa361SAndroid Build Coastguard Worker  *
43*344aa361SAndroid Build Coastguard Worker  * Specifically, vscnprintf will use printf semantics to expand @fmt with
44*344aa361SAndroid Build Coastguard Worker  * @args, writing the first @size characters to the buffer.
45*344aa361SAndroid Build Coastguard Worker  *
46*344aa361SAndroid Build Coastguard Worker  * Return: The number of characters written to the buffer.
47*344aa361SAndroid Build Coastguard Worker  */
48*344aa361SAndroid Build Coastguard Worker __attribute__((__format__ (__printf__, 3, 0))) /* */
49*344aa361SAndroid Build Coastguard Worker int vscnprintf(char* buf, size_t size, const char* fmt, va_list args);
50*344aa361SAndroid Build Coastguard Worker 
51*344aa361SAndroid Build Coastguard Worker __END_CDECLS
52