diff --git a/source/common.c b/source/common.c index 0b275b9..83624ce 100644 --- a/source/common.c +++ b/source/common.c @@ -132,6 +132,25 @@ void InsertLinkAfter (link_t *l, link_t *after) ============================================================================ */ +#define snprintf_func snprintf +#define vsnprintf_func vsnprintf + +int q_vsnprintf(char *str, size_t size, const char *format, va_list args) +{ + int ret; + + ret = vsnprintf_func (str, size, format, args); + + if (ret < 0) + ret = (int)size; + if (size == 0) /* no buffer */ + return ret; + if ((size_t)ret >= size) + str[size - 1] = '\0'; + + return ret; +} + int q_snprintf (char *str, size_t size, const char *format, ...) { int ret; diff --git a/source/common.h b/source/common.h index 35e50e7..680a4f2 100644 --- a/source/common.h +++ b/source/common.h @@ -155,6 +155,8 @@ int Q_strcasecmp (char *s1, char *s2); int Q_strncasecmp (char *s1, char *s2, int n); int Q_atoi (char *str); float Q_atof (char *str); +int q_snprintf (char *str, size_t size, const char *format, ...); +int q_vsnprintf(char *str, size_t size, const char *format, va_list args); //============================================================================