diff options
author | Leah Neukirchen <leah@vuxu.org> | 2021-11-05 18:52:11 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2021-11-05 18:52:46 +0100 |
commit | 75ea20675d012e692996bc6beae9149b0deb08b0 (patch) | |
tree | ab1569403e1c5f8e76f5f93f969a3335275c54a5 /steprn.c | |
download | libste-75ea20675d012e692996bc6beae9149b0deb08b0.tar.gz libste-75ea20675d012e692996bc6beae9149b0deb08b0.tar.xz libste-75ea20675d012e692996bc6beae9149b0deb08b0.zip |
initial commit
Diffstat (limited to 'steprn.c')
-rw-r--r-- | steprn.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/steprn.c b/steprn.c new file mode 100644 index 0000000..2ca0a27 --- /dev/null +++ b/steprn.c @@ -0,0 +1,23 @@ +#include <stdarg.h> +#include <stdio.h> + +char * +steprn(char *dst, char *end, const char *fmt, ...) +{ + if (dst >= end) + return end; + + va_list ap; + va_start(ap, fmt); + int r = vsnprintf(dst, end - dst, fmt, ap); + va_end(ap); + + if (r < 0) { + /* snprintf only fails for silly reasons: + truncate what was written, behave as noop. */ + *dst = 0; + return dst; + } + + return r > end - dst ? end : dst + r; +} |