Commit 47ea7148 authored by Bruce Momjian's avatar Bruce Momjian

Fix snprintf on Win32:

 *  If vsnprintf() is not before snprintf() in this file, snprintf()
 *  will call the system vsnprintf() on MinGW.
parent 9989e904
...@@ -66,28 +66,27 @@ ...@@ -66,28 +66,27 @@
* causing nasty effects. * causing nasty effects.
**************************************************************/ **************************************************************/
/*static char _id[] = "$PostgreSQL: pgsql/src/port/snprintf.c,v 1.10 2005/03/02 00:02:13 momjian Exp $";*/ /*static char _id[] = "$PostgreSQL: pgsql/src/port/snprintf.c,v 1.11 2005/03/02 03:21:52 momjian Exp $";*/
int snprintf(char *str, size_t count, const char *fmt,...); int snprintf(char *str, size_t count, const char *fmt,...);
int vsnprintf(char *str, size_t count, const char *fmt, va_list args); int vsnprintf(char *str, size_t count, const char *fmt, va_list args);
int printf(const char *format, ...); int printf(const char *format, ...);
static void dopr(char *buffer, const char *format, va_list args, char *end); static void dopr(char *buffer, const char *format, va_list args, char *end);
/*
* If vsnprintf() is not before snprintf() in this file, snprintf()
* will call the system vsnprintf() on MinGW.
*/
int int
printf(const char *fmt,...) vsnprintf(char *str, size_t count, const char *fmt, va_list args)
{ {
int len; char *end;
va_list args; str[0] = '\0';
char* buffer[4096]; end = str + count - 1;
char* p; dopr(str, fmt, args, end);
if (count > 0)
va_start(args, fmt); end[0] = '\0';
len = vsnprintf((char*)buffer, (size_t)4096, fmt, args); return strlen(str);
va_end(args);
p = (char*)buffer;
for(;*p;p++)
putchar(*p);
return len;
} }
int int
...@@ -102,17 +101,21 @@ snprintf(char *str, size_t count, const char *fmt,...) ...@@ -102,17 +101,21 @@ snprintf(char *str, size_t count, const char *fmt,...)
return len; return len;
} }
int int
vsnprintf(char *str, size_t count, const char *fmt, va_list args) printf(const char *fmt,...)
{ {
char *end; int len;
str[0] = '\0'; va_list args;
end = str + count - 1; char* buffer[4096];
dopr(str, fmt, args, end); char* p;
if (count > 0)
end[0] = '\0'; va_start(args, fmt);
return strlen(str); len = vsnprintf((char*)buffer, (size_t)4096, fmt, args);
va_end(args);
p = (char*)buffer;
for(;*p;p++)
putchar(*p);
return len;
} }
/* /*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment