Overview ======== Small and simple snprintf implementation without dynamic memory allocations. Syntax ====== int ssnprintf(char *str, size_t size, const char *fmt, ...); int svsnprintf(char *str, size_t size, const char *fmt, va_list ap); Where conversion specification can be: flags: 0, -, + width: NUMBER or * precision: NUMBER or * length modifier: hh, h, l, ll conversion specifier: d, i, o, u, x, X, b(binary form), f, c, s, p Build ===== Just: make Examples ======== Fill a buffer with a data: int fill_buf(char **data, char *buf, int buf_size) { int n, rem; char *pos; rem = buf_size; pos = buf; for(int i = 0; data[i]; i++) { n = ssprintf(pos, rem, "data: %s\n", data[i]); pos += n; rem -= (n < rem) ? n : rem; } /* If a buffer is completely filled, then data length is buf_size - 1 */ if (rem == 0) rem++; return buf_size - rem; } Note ==== The code is written for I32LP64 data model: - max unsigned long long int must exist(necessary for lib) - max unsigned long int must be (2^64 - 1)(necessary for tests) - max unsigned int must be (2^32 - 1)(necessary for tests)
lego12239/svsnprintf
Small and simple snprintf implementation without dynamic memory allocations.
CBSD-3-Clause