MCPcopy Create free account
hub / github.com/apache/nuttx / snprintf

Function snprintf

libs/libc/stdio/lib_snprintf.c:37–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35 ****************************************************************************/
36
37int snprintf(FAR char *buf, size_t size, FAR const IPTR char *format, ...)
38{
39 union
40 {
41 struct lib_outstream_s nulloutstream;
42 struct lib_memoutstream_s memoutstream;
43 } u;
44
45 FAR struct lib_outstream_s *stream;
46 va_list ap;
47 int n;
48
49 /* "If the value of [size] is zero on a call to snprintf(), nothing shall
50 * be written, the number of bytes that would have been written had [size]
51 * been sufficiently large excluding the terminating null shall be
52 * returned, and [buf] may be a null pointer." -- opengroup.org
53 */
54
55 if (size > 0)
56 {
57 /* Initialize a memory stream to write to the buffer */
58
59 lib_memoutstream(&u.memoutstream, buf, size);
60 stream = &u.memoutstream.common;
61 }
62 else
63 {
64 /* Use a null stream to get the size of the buffer */
65
66 lib_nulloutstream(&u.nulloutstream);
67 stream = &u.nulloutstream;
68 }
69
70 /* Then let lib_vsprintf do the real work */
71
72 va_start(ap, format);
73 n = lib_vsprintf(stream, format, ap);
74 va_end(ap);
75 return n;
76}

Callers 15

tmpnamFunction · 0.70
nx_disconnectFunction · 0.50
nx_connectinstanceFunction · 0.50
sched_dumpstackFunction · 0.50
dcngettextFunction · 0.50
rexec_afFunction · 0.50
getnameinfoFunction · 0.50
gai_strerrorFunction · 0.50
alloc_aiFunction · 0.50
ptsname_rFunction · 0.50
posix_openptFunction · 0.50
ftokFunction · 0.50

Calls 3

lib_memoutstreamFunction · 0.85
lib_nulloutstreamFunction · 0.85
lib_vsprintfFunction · 0.85

Tested by

no test coverage detected