Fix for HAVE_LONG bug in snprintf.c.
This commit is contained in:
parent
6b7cf13200
commit
9d6f0606c5
@ -41,9 +41,6 @@
|
|||||||
#include "regex/cdefs.h"
|
#include "regex/cdefs.h"
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#define VA_LOCAL_DECL va_list args;
|
|
||||||
#define VA_START(f) va_start(args, f)
|
|
||||||
#define VA_END va_end(args)
|
|
||||||
|
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
@ -75,34 +72,30 @@ typedef long long long_long;
|
|||||||
* causing nast effects.
|
* causing nast effects.
|
||||||
**************************************************************/
|
**************************************************************/
|
||||||
|
|
||||||
/*static char _id[] = "$Id: snprintf.c,v 1.12 1998/12/18 06:59:39 momjian Exp $";*/
|
/*static char _id[] = "$Id: snprintf.c,v 1.13 1998/12/18 07:03:06 momjian Exp $";*/
|
||||||
static char *end;
|
static char *end;
|
||||||
static int SnprfOverflow;
|
static int SnprfOverflow;
|
||||||
|
|
||||||
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,...);
|
int vsnprintf(char *str, size_t count, const char *fmt, va_list args);
|
||||||
static void dopr(char *buffer, const char *format,...);
|
static void dopr(char *buffer, const char *format, va_list args);
|
||||||
|
|
||||||
int
|
int
|
||||||
snprintf(char *str, size_t count, const char *fmt,...)
|
snprintf(char *str, size_t count, const char *fmt,...)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
|
va_list args;
|
||||||
|
|
||||||
VA_LOCAL_DECL
|
va_start(args, fmt);
|
||||||
|
|
||||||
VA_START(fmt);
|
|
||||||
len = vsnprintf(str, count, fmt, args);
|
len = vsnprintf(str, count, fmt, args);
|
||||||
VA_END;
|
va_end(args);
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
vsnprintf(char *str, size_t count, const char *fmt,...)
|
vsnprintf(char *str, size_t count, const char *fmt, va_list args)
|
||||||
{
|
{
|
||||||
VA_LOCAL_DECL
|
|
||||||
|
|
||||||
VA_START(fmt);
|
|
||||||
str[0] = 0;
|
str[0] = 0;
|
||||||
end = str + count - 1;
|
end = str + count - 1;
|
||||||
SnprfOverflow = 0;
|
SnprfOverflow = 0;
|
||||||
@ -112,7 +105,6 @@ vsnprintf(char *str, size_t count, const char *fmt,...)
|
|||||||
if (SnprfOverflow)
|
if (SnprfOverflow)
|
||||||
elog(NOTICE, "vsnprintf overflow, len = %d, str = %s",
|
elog(NOTICE, "vsnprintf overflow, len = %d, str = %s",
|
||||||
count, str);
|
count, str);
|
||||||
VA_END;
|
|
||||||
return strlen(str);
|
return strlen(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,7 +114,7 @@ vsnprintf(char *str, size_t count, const char *fmt,...)
|
|||||||
|
|
||||||
static void fmtstr __P((char *value, int ljust, int len, int zpad, int maxwidth));
|
static void fmtstr __P((char *value, int ljust, int len, int zpad, int maxwidth));
|
||||||
|
|
||||||
#ifndef HAVE_LONG_LONG_INT_64
|
#ifndef HAVE_LONG_INT_64
|
||||||
static void fmtnum __P((long value, int base, int dosign, int ljust, int len, int zpad));
|
static void fmtnum __P((long value, int base, int dosign, int ljust, int len, int zpad));
|
||||||
#else
|
#else
|
||||||
static void fmtnum __P((long_long value, int base, int dosign, int ljust, int len, int zpad));
|
static void fmtnum __P((long_long value, int base, int dosign, int ljust, int len, int zpad));
|
||||||
@ -133,16 +125,16 @@ static char *output;
|
|||||||
static void dopr_outch __P((int c));
|
static void dopr_outch __P((int c));
|
||||||
|
|
||||||
static void
|
static void
|
||||||
dopr(char *buffer, const char *format,...)
|
dopr(char *buffer, const char *format, va_list args)
|
||||||
{
|
{
|
||||||
int ch;
|
int ch;
|
||||||
#ifdef HAVE_LONG_LONG_INT_64
|
#ifdef HAVE_LONG_LONG_INT_64
|
||||||
long_long value;
|
long_long value;
|
||||||
|
int longlongflag = 0;
|
||||||
#else
|
#else
|
||||||
long value;
|
long value;
|
||||||
#endif
|
#endif
|
||||||
int longflag = 0;
|
int longflag = 0;
|
||||||
int longlongflag = 0;
|
|
||||||
int pointflag = 0;
|
int pointflag = 0;
|
||||||
int maxwidth = 0;
|
int maxwidth = 0;
|
||||||
char *strvalue;
|
char *strvalue;
|
||||||
@ -150,10 +142,6 @@ dopr(char *buffer, const char *format,...)
|
|||||||
int len;
|
int len;
|
||||||
int zpad;
|
int zpad;
|
||||||
|
|
||||||
VA_LOCAL_DECL
|
|
||||||
|
|
||||||
VA_START(format);
|
|
||||||
|
|
||||||
output = buffer;
|
output = buffer;
|
||||||
while ((ch = *format++))
|
while ((ch = *format++))
|
||||||
{
|
{
|
||||||
@ -162,13 +150,15 @@ dopr(char *buffer, const char *format,...)
|
|||||||
case '%':
|
case '%':
|
||||||
ljust = len = zpad = maxwidth = 0;
|
ljust = len = zpad = maxwidth = 0;
|
||||||
longflag = pointflag = 0;
|
longflag = pointflag = 0;
|
||||||
|
#ifdef HAVE_LONG_LONG_INT_64
|
||||||
|
longlongflag = 0;
|
||||||
|
#endif
|
||||||
nextch:
|
nextch:
|
||||||
ch = *format++;
|
ch = *format++;
|
||||||
switch (ch)
|
switch (ch)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
dostr("**end of format**", 0);
|
dostr("**end of format**", 0);
|
||||||
VA_END;
|
|
||||||
return;
|
return;
|
||||||
case '-':
|
case '-':
|
||||||
ljust = 1;
|
ljust = 1;
|
||||||
@ -200,16 +190,13 @@ dopr(char *buffer, const char *format,...)
|
|||||||
pointflag = 1;
|
pointflag = 1;
|
||||||
goto nextch;
|
goto nextch;
|
||||||
case 'l':
|
case 'l':
|
||||||
|
#ifdef HAVE_LONG_LONG_INT_64
|
||||||
if (longflag)
|
if (longflag)
|
||||||
{
|
|
||||||
longlongflag = 1;
|
longlongflag = 1;
|
||||||
goto nextch;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
#endif
|
||||||
longflag = 1;
|
longflag = 1;
|
||||||
goto nextch;
|
goto nextch;
|
||||||
}
|
|
||||||
case 'u':
|
case 'u':
|
||||||
case 'U':
|
case 'U':
|
||||||
/* fmtnum(value,base,dosign,ljust,len,zpad) */
|
/* fmtnum(value,base,dosign,ljust,len,zpad) */
|
||||||
@ -255,6 +242,7 @@ dopr(char *buffer, const char *format,...)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
value = va_arg(args, int);
|
value = va_arg(args, int);
|
||||||
|
|
||||||
fmtnum(value, 10, 1, ljust, len, zpad);
|
fmtnum(value, 10, 1, ljust, len, zpad);
|
||||||
break;
|
break;
|
||||||
case 'x':
|
case 'x':
|
||||||
@ -311,7 +299,6 @@ dopr(char *buffer, const char *format,...)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
*output = 0;
|
*output = 0;
|
||||||
VA_END;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -362,7 +349,7 @@ int base,
|
|||||||
zpad;
|
zpad;
|
||||||
{
|
{
|
||||||
int signvalue = 0;
|
int signvalue = 0;
|
||||||
#ifdef HAVE_LONG_LONG_INT_64
|
#ifdef HAVE_LONG_INT_64
|
||||||
unsigned long_long uvalue;
|
unsigned long_long uvalue;
|
||||||
#else
|
#else
|
||||||
unsigned long uvalue;
|
unsigned long uvalue;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user