2017-05-19 23:37:19 +02:00
|
|
|
static inline int nsock_vprintf(int sd, const char *fmt, va_list ap, int plus)
|
|
|
|
{
|
|
|
|
char buf[4096];
|
|
|
|
int len;
|
|
|
|
|
|
|
|
/* -2 to accommodate vsnprintf()'s which don't include nul on overflow */
|
|
|
|
len = vsnprintf(buf, sizeof(buf) - 2, fmt, ap);
|
2019-04-18 17:09:18 +02:00
|
|
|
if (len < 0) {
|
2017-05-19 23:37:19 +02:00
|
|
|
return len;
|
2019-04-18 17:09:18 +02:00
|
|
|
}
|
|
|
|
|
2017-05-19 23:37:19 +02:00
|
|
|
buf[len] = 0;
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
int nsock_printf_nul(int sd, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
ret = nsock_vprintf(sd, fmt, ap, 1);
|
|
|
|
va_end(ap);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-04-18 17:09:18 +02:00
|
|
|
int nsock_printf(int sd, const char *fmt, ...)
|
|
|
|
{
|
2017-05-19 23:37:19 +02:00
|
|
|
va_list ap;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
ret = nsock_vprintf(sd, fmt, ap, 0);
|
|
|
|
va_end(ap);
|
|
|
|
return ret;
|
|
|
|
}
|