A fast, lightweight and minimalistic Wayland terminal emulator
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
928 B

#include "xsnprintf.h"
#include <limits.h>
#include <stdio.h>
#include "debug.h"
xvsnprintf(char *buf, size_t n, const char *format, va_list ap)
xassert(n <= INT_MAX);
int len = vsnprintf(buf, n, format, ap);
* ISO C11 § states:
* "The snprintf function returns the number of characters that
* would have been written had n been sufficiently large, not
* counting the terminating null character, or a negative value
* if an encoding error occurred. Thus, the null-terminated output
* has been completely written if and only if the returned value
* is nonnegative and less than n."
xassert(len >= 0);
xassert(len < (int)n);
return (size_t)len;
xsnprintf(char *buf, size_t n, const char *format, ...)
va_list ap;
va_start(ap, format);
size_t len = xvsnprintf(buf, n, format, ap);
return len;