rbtree: add rb_search_exact()
[nasm.git] / stdlib / vsnprintf.c
blob284cc19424324a4592a35c68b475228c65761609
1 /*
2 * vsnprintf()
4 * Poor substitute for a real vsnprintf() function for systems
5 * that don't have them...
6 */
8 #include "compiler.h"
11 #include "nasmlib.h"
12 #include "error.h"
14 #if !defined(HAVE_VSNPRINTF) && !defined(HAVE__VSNPRINTF)
16 #define BUFFER_SIZE 65536 /* Bigger than any string we might print... */
18 static char snprintf_buffer[BUFFER_SIZE];
20 int vsnprintf(char *str, size_t size, const char *format, va_list ap)
22 int rv, bytes;
24 if (size > BUFFER_SIZE) {
25 nasm_panic("vsnprintf: size (%d) > BUFFER_SIZE (%d)",
26 size, BUFFER_SIZE);
27 size = BUFFER_SIZE;
30 rv = vsprintf(snprintf_buffer, format, ap);
31 if (rv >= BUFFER_SIZE)
32 nasm_panic("vsnprintf buffer overflow");
34 if (size > 0) {
35 if ((size_t)rv < size-1)
36 bytes = rv;
37 else
38 bytes = size-1;
39 memcpy(str, snprintf_buffer, bytes);
40 str[bytes] = '\0';
43 return rv;
46 #endif