Skip to content

Commit 47ea714

Browse files
committed
Fix snprintf on Win32:
* If vsnprintf() is not before snprintf() in this file, snprintf() * will call the system vsnprintf() on MinGW.
1 parent 9989e90 commit 47ea714

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

src/port/snprintf.c

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -66,28 +66,27 @@
6666
* causing nasty effects.
6767
**************************************************************/
6868

69-
/*static char _id[] = "$PostgreSQL: pgsql/src/port/snprintf.c,v 1.10 2005/03/02 00:02:13 momjian Exp $";*/
69+
/*static char _id[] = "$PostgreSQL: pgsql/src/port/snprintf.c,v 1.11 2005/03/02 03:21:52 momjian Exp $";*/
7070

7171
int snprintf(char *str, size_t count, const char *fmt,...);
7272
int vsnprintf(char *str, size_t count, const char *fmt, va_list args);
7373
int printf(const char *format, ...);
7474
static void dopr(char *buffer, const char *format, va_list args, char *end);
7575

76+
/*
77+
* If vsnprintf() is not before snprintf() in this file, snprintf()
78+
* will call the system vsnprintf() on MinGW.
79+
*/
7680
int
77-
printf(const char *fmt,...)
81+
vsnprintf(char *str, size_t count, const char *fmt, va_list args)
7882
{
79-
int len;
80-
va_list args;
81-
char* buffer[4096];
82-
char* p;
83-
84-
va_start(args, fmt);
85-
len = vsnprintf((char*)buffer, (size_t)4096, fmt, args);
86-
va_end(args);
87-
p = (char*)buffer;
88-
for(;*p;p++)
89-
putchar(*p);
90-
return len;
83+
char *end;
84+
str[0] = '\0';
85+
end = str + count - 1;
86+
dopr(str, fmt, args, end);
87+
if (count > 0)
88+
end[0] = '\0';
89+
return strlen(str);
9190
}
9291

9392
int
@@ -102,17 +101,21 @@ snprintf(char *str, size_t count, const char *fmt,...)
102101
return len;
103102
}
104103

105-
106104
int
107-
vsnprintf(char *str, size_t count, const char *fmt, va_list args)
105+
printf(const char *fmt,...)
108106
{
109-
char *end;
110-
str[0] = '\0';
111-
end = str + count - 1;
112-
dopr(str, fmt, args, end);
113-
if (count > 0)
114-
end[0] = '\0';
115-
return strlen(str);
107+
int len;
108+
va_list args;
109+
char* buffer[4096];
110+
char* p;
111+
112+
va_start(args, fmt);
113+
len = vsnprintf((char*)buffer, (size_t)4096, fmt, args);
114+
va_end(args);
115+
p = (char*)buffer;
116+
for(;*p;p++)
117+
putchar(*p);
118+
return len;
116119
}
117120

118121
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy