* causing nasty effects.
**************************************************************/
-/*static char _id[] = "$PostgreSQL: pgsql/src/port/snprintf.c,v 1.9 2005/03/01 05:47:28 momjian Exp $";*/
+/*static char _id[] = "$PostgreSQL: pgsql/src/port/snprintf.c,v 1.10 2005/03/02 00:02:13 momjian Exp $";*/
int snprintf(char *str, size_t count, const char *fmt,...);
int vsnprintf(char *str, size_t count, const char *fmt, va_list args);
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);
int
printf(const char *fmt,...)
* dopr(): poor man's version of doprintf
*/
-static void fmtstr(char *value, int ljust, int len, int zpad, int maxwidth, char *end);
-static void fmtnum(int64 value, int base, int dosign, int ljust, int len, int zpad, char *end);
-static void fmtfloat(double value, char type, int ljust, int len, int precision, int pointflag, char *end);
-static void dostr(char *str, int cut, char *end);
-static void dopr_outch(int c, char *end);
-
-static char *output;
+static void fmtstr(char *value, int ljust, int len, int zpad, int maxwidth,
+ char *end, char **output);
+static void fmtnum(int64 value, int base, int dosign, int ljust, int len,
+ int zpad, char *end, char **output);
+static void fmtfloat(double value, char type, int ljust, int len,
+ int precision, int pointflag, char *end, char **output);
+static void dostr(char *str, int cut, char *end, char **output);
+static void dopr_outch(int c, char *end, char **output);
#define FMTSTR 1
#define FMTNUM 2
int fmtpos = 1;
int realpos = 0;
int position;
- static struct{
+ char *output;
+ /* In thread mode this structure is too large. */
+#ifndef ENABLE_THREAD_SAFETY
+ static
+#endif
+ struct{
const char* fmtbegin;
const char* fmtend;
void* value;
goto nextch;
case 'u':
case 'U':
- /* fmtnum(value,base,dosign,ljust,len,zpad) */
+ /* fmtnum(value,base,dosign,ljust,len,zpad,&output) */
if (longflag)
{
if (longlongflag)
break;
case 'o':
case 'O':
- /* fmtnum(value,base,dosign,ljust,len,zpad) */
+ /* fmtnum(value,base,dosign,ljust,len,zpad,&output) */
if (longflag)
{
if (longlongflag)
if (longflag)
{
if (longlongflag)
+ {
value = va_arg(args, int64);
+ }
else
value = va_arg(args, long);
}
case '%':
break;
default:
- dostr("???????", 0, end);
+ dostr("???????", 0, end, &output);
}
break;
default:
- dopr_outch(ch, end);
+ dopr_outch(ch, end, &output);
break;
}
}
case FMTSTR:
fmtstr(fmtparptr[i]->value, fmtparptr[i]->ljust,
fmtparptr[i]->len, fmtparptr[i]->zpad,
- fmtparptr[i]->maxwidth, end);
+ fmtparptr[i]->maxwidth, end, &output);
break;
case FMTNUM:
fmtnum(fmtparptr[i]->numvalue, fmtparptr[i]->base,
fmtparptr[i]->dosign, fmtparptr[i]->ljust,
- fmtparptr[i]->len, fmtparptr[i]->zpad, end);
+ fmtparptr[i]->len, fmtparptr[i]->zpad, end, &output);
break;
case FMTFLOAT:
fmtfloat(fmtparptr[i]->fvalue, fmtparptr[i]->type,
fmtparptr[i]->ljust, fmtparptr[i]->len,
fmtparptr[i]->precision, fmtparptr[i]->pointflag,
- end);
+ end, &output);
break;
case FMTCHAR:
- dopr_outch(fmtparptr[i]->charvalue, end);
+ dopr_outch(fmtparptr[i]->charvalue, end, &output);
break;
}
format = fmtpar[i].fmtend;
goto nochar;
}
}
- dopr_outch(ch, end);
+ dopr_outch(ch, end, &output);
nochar:
/* nothing */
; /* semicolon required because a goto has to be attached to a statement */
}
static void
-fmtstr(char *value, int ljust, int len, int zpad, int maxwidth, char *end)
+fmtstr(char *value, int ljust, int len, int zpad, int maxwidth, char *end,
+ char **output)
{
int padlen,
strlen; /* amount to pad */
padlen = -padlen;
while (padlen > 0)
{
- dopr_outch(' ', end);
+ dopr_outch(' ', end, output);
--padlen;
}
- dostr(value, maxwidth, end);
+ dostr(value, maxwidth, end, output);
while (padlen < 0)
{
- dopr_outch(' ', end);
+ dopr_outch(' ', end, output);
++padlen;
}
}
static void
-fmtnum(int64 value, int base, int dosign, int ljust, int len, int zpad, char *end)
+fmtnum(int64 value, int base, int dosign, int ljust, int len, int zpad,
+ char *end, char **output)
{
int signvalue = 0;
uint64 uvalue;
{
if (signvalue)
{
- dopr_outch(signvalue, end);
+ dopr_outch(signvalue, end, output);
--padlen;
signvalue = 0;
}
while (padlen > 0)
{
- dopr_outch(zpad, end);
+ dopr_outch(zpad, end, output);
--padlen;
}
}
while (padlen > 0)
{
- dopr_outch(' ', end);
+ dopr_outch(' ', end, output);
--padlen;
}
if (signvalue)
- dopr_outch(signvalue, end);
+ dopr_outch(signvalue, end, output);
while (place > 0)
- dopr_outch(convert[--place], end);
+ dopr_outch(convert[--place], end, output);
while (padlen < 0)
{
- dopr_outch(' ', end);
+ dopr_outch(' ', end, output);
++padlen;
}
}
static void
-fmtfloat(double value, char type, int ljust, int len, int precision, int pointflag, char *end)
+fmtfloat(double value, char type, int ljust, int len, int precision,
+ int pointflag, char *end, char **output)
{
char fmt[32];
char convert[512];
while (padlen > 0)
{
- dopr_outch(' ', end);
+ dopr_outch(' ', end, output);
--padlen;
}
- dostr(convert, 0, end);
+ dostr(convert, 0, end, output);
while (padlen < 0)
{
- dopr_outch(' ', end);
+ dopr_outch(' ', end, output);
++padlen;
}
}
static void
-dostr(char *str, int cut, char *end)
+dostr(char *str, int cut, char *end, char **output)
{
if (cut)
{
while (*str && cut-- > 0)
- dopr_outch(*str++, end);
+ dopr_outch(*str++, end, output);
}
else
{
while (*str)
- dopr_outch(*str++, end);
+ dopr_outch(*str++, end, output);
}
}
static void
-dopr_outch(int c, char *end)
+dopr_outch(int c, char *end, char **output)
{
#ifdef NOT_USED
if (iscntrl((unsigned char) c) && c != '\n' && c != '\t')
{
c = '@' + (c & 0x1F);
- if (end == 0 || output < end)
- *output++ = '^';
+ if (end == 0 || *output < end)
+ *(*output)++ = '^';
}
#endif
- if (end == 0 || output < end)
- *output++ = c;
+ if (end == 0 || *output < end)
+ *(*output)++ = c;
}