summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSascha Schumann <sas@php.net>2002-05-07 05:26:30 +0000
committerSascha Schumann <sas@php.net>2002-05-07 05:26:30 +0000
commit946fca9c91d7743441d7c46461fb6035168e2d44 (patch)
tree73b6e2e9b98bb1e276007ad572c3451f90083c45
parentabc72f2820a811a0e5d6189bfd7e73fc46f9561a (diff)
downloadphp-git-946fca9c91d7743441d7c46461fb6035168e2d44.tar.gz
Add thread-safety to some conversion functions and sync a bit with
APR.
-rw-r--r--main/snprintf.c34
-rw-r--r--main/snprintf.h16
2 files changed, 26 insertions, 24 deletions
diff --git a/main/snprintf.c b/main/snprintf.c
index f4cd19838d..bf14e904c5 100644
--- a/main/snprintf.c
+++ b/main/snprintf.c
@@ -88,7 +88,7 @@
* is declared as buf[ 100 ], buf_end should be &buf[ 100 ])
*/
char *
- ap_php_conv_10(register wide_int num, register bool_int is_unsigned,
+ap_php_conv_10(register wide_int num, register bool_int is_unsigned,
register bool_int * is_negative, char *buf_end, register int *len)
{
register char *p = buf_end;
@@ -147,17 +147,19 @@ char *
register char *s = buf;
register char *p;
int decimal_point;
+ char buf1[NDIG];
if (format == 'f')
- p = ap_php_fcvt(num, precision, &decimal_point, is_negative);
+ p = ap_php_fcvt(num, precision, &decimal_point, is_negative, buf1);
else /* either e or E format */
- p = ap_php_ecvt(num, precision + 1, &decimal_point, is_negative);
+ p = ap_php_ecvt(num, precision + 1, &decimal_point, is_negative, buf1);
/*
* Check for Infinity and NaN
*/
if (isalpha((int)*p)) {
- *len = strlen(strcpy(buf, p));
+ *len = strlen(p);
+ memcpy(buf, p, *len + 1);
*is_negative = FALSE;
return (buf);
}
@@ -274,12 +276,11 @@ char *
#define NDIG 80
char *
- ap_php_cvt(double arg, int ndigits, int *decpt, int *sign, int eflag)
+ap_php_cvt(double arg, int ndigits, int *decpt, int *sign, int eflag, char *buf)
{
register int r2;
double fi, fj;
register char *p, *p1;
- static char buf[NDIG];
if (ndigits >= NDIG - 1)
ndigits = NDIG - 2;
@@ -319,8 +320,7 @@ char *
return (buf);
}
while (p <= p1 && p < &buf[NDIG]) {
- arg *= 10;
- arg = modf(arg, &fj);
+ arg = modf(arg * 10, &fj);
*p++ = (int) fj + '0';
}
if (p1 >= &buf[NDIG]) {
@@ -348,15 +348,15 @@ char *
}
char *
- ap_php_ecvt(double arg, int ndigits, int *decpt, int *sign)
+ap_php_ecvt(double arg, int ndigits, int *decpt, int *sign, char *buf)
{
- return (ap_php_cvt(arg, ndigits, decpt, sign, 1));
+ return (ap_php_cvt(arg, ndigits, decpt, sign, 1, buf));
}
char *
- ap_php_fcvt(double arg, int ndigits, int *decpt, int *sign)
+ap_php_fcvt(double arg, int ndigits, int *decpt, int *sign, char *buf)
{
- return (ap_php_cvt(arg, ndigits, decpt, sign, 0));
+ return (ap_php_cvt(arg, ndigits, decpt, sign, 0, buf));
}
/*
@@ -365,13 +365,14 @@ char *
*/
char *
- ap_php_gcvt(double number, int ndigit, char *buf)
+ap_php_gcvt(double number, int ndigit, char *buf, boolean_e altform)
{
int sign, decpt;
register char *p1, *p2;
register i;
+ char buf1[NDIG];
- p1 = ap_php_ecvt(number, ndigit, &decpt, &sign);
+ p1 = ap_php_ecvt(number, ndigit, &decpt, &sign, buf1);
p2 = buf;
if (sign)
*p2++ = '-';
@@ -415,7 +416,7 @@ char *
*p2++ = '.';
}
}
- if (p2[-1] == '.')
+ if (p2[-1] == '.' && !altform)
p2--;
*p2 = '\0';
return (buf);
@@ -762,7 +763,8 @@ static int format_converter(register buffy * odp, const char *fmt,
/*
* * We use &num_buf[ 1 ], so that we have room for the sign
*/
- s = ap_php_gcvt(va_arg(ap, double), precision, &num_buf[1]);
+ s = ap_php_gcvt(va_arg(ap, double), precision, &num_buf[1],
+ alternate_form);
if (*s == '-')
prefix_char = *s++;
else if (print_sign)
diff --git a/main/snprintf.h b/main/snprintf.h
index d05d8646d0..1efa77f122 100644
--- a/main/snprintf.h
+++ b/main/snprintf.h
@@ -34,6 +34,10 @@ int php_sprintf (char* s, const char* format, ...);
#define sprintf php_sprintf
#endif
+typedef enum {
+ NO = 0, YES = 1
+} boolean_e;
+
#ifdef HAVE_GCVT
#define ap_php_ecvt ecvt
@@ -42,17 +46,13 @@ int php_sprintf (char* s, const char* format, ...);
#else
-extern char * ap_php_cvt(double arg, int ndigits, int *decpt, int *sign, int eflag);
-extern char * ap_php_ecvt(double arg, int ndigits, int *decpt, int *sign);
-extern char * ap_php_fcvt(double arg, int ndigits, int *decpt, int *sign);
-extern char * ap_php_gcvt(double number, int ndigit, char *buf);
+extern char * ap_php_cvt(double arg, int ndigits, int *decpt, int *sign, int eflag, char *buf);
+extern char * ap_php_ecvt(double arg, int ndigits, int *decpt, int *sign, char *buf);
+extern char * ap_php_fcvt(double arg, int ndigits, int *decpt, int *sign, char *buf);
+extern char * ap_php_gcvt(double number, int ndigit, char *buf, boolean_e altform);
#endif
-typedef enum {
- NO = 0, YES = 1
-} boolean_e;
-
#define WIDE_INT long
typedef WIDE_INT wide_int;
typedef unsigned WIDE_INT u_wide_int;