MCPcopy Create free account
hub / github.com/acl-dev/acl / acl_vsnprintf

Function acl_vsnprintf

lib_acl/src/stdlib/acl_vsprintf.c:157–386  ·  view source on GitHub ↗

* vsnprintf - Format a string and place it in a buffer * @buf: The buffer to place the result into * @size: The size of the buffer, including the trailing null space * @fmt: The format string to use * @args: Arguments for the format string * * Call this function if you are already dealing with a va_list. * You probably want snprintf instead. */

Source from the content-addressed store, hash-verified

155* You probably want snprintf instead.
156 */
157int acl_vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
158{
159 int len;
160 long int num;
161 int i, base;
162 char *str, *end, c;
163 const char *s;
164
165 int flags; /* flags to number() */
166
167 int field_width; /* width of output field */
168 int precision; /* min. # of digits for integers; max
169 number of chars for from string */
170 int qualifier; /* 'h', 'l', or 'L' for integer fields */
171 /* 'z' support added 23/7/1999 S.H. */
172 /* 'z' changed to 'Z' --davidm 1/25/99 */
173
174 str = buf;
175 end = buf + size - 1;
176
177 if (end < buf - 1) {
178 end = ((void *) -1);
179 size = end - buf + 1;
180 }
181
182 for (; *fmt ; ++fmt) {
183 if (*fmt != '%') {
184 if (str <= end)
185 *str = *fmt;
186 ++str;
187 continue;
188 }
189
190 /* process flags */
191 flags = 0;
192 repeat:
193 ++fmt; /* this also skips first '%' */
194 switch (*fmt) {
195 case '-': flags |= LEFT; goto repeat;
196 case '+': flags |= PLUS; goto repeat;
197 case ' ': flags |= SPACE; goto repeat;
198 case '#': flags |= SPECIAL; goto repeat;
199 case '0': flags |= ZEROPAD; goto repeat;
200 }
201
202 /* get field width */
203 field_width = -1;
204 if (isdigit((int)(*fmt)))
205 field_width = skip_atoi(&fmt);
206 else if (*fmt == '*') {
207 ++fmt;
208 /* it's the next argument */
209 field_width = va_arg(args, int);
210 if (field_width < 0) {
211 field_width = -field_width;
212 flags |= LEFT;
213 }
214 }

Callers 4

acl_snprintfFunction · 0.85
acl_vsprintfFunction · 0.85
msg_infoFunction · 0.85
msg_errorFunction · 0.85

Calls 3

skip_atoiFunction · 0.85
acl_strnlenFunction · 0.85
numberFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…