Back to index

php5  5.3.10
Defines | Typedefs | Enumerations | Functions
snprintf.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define slprintf   ap_php_slprintf
#define vslprintf   ap_php_vslprintf
#define snprintf   ap_php_snprintf
#define vsnprintf   ap_php_vsnprintf
#define vasprintf   ap_php_vasprintf
#define asprintf   ap_php_asprintf
#define sprintf   php_sprintf
#define WIDE_INT   long
#define FORMAT_CONV_MAX_PRECISION   500

Typedefs

typedef int bool_int
typedef WIDE_INT wide_int
typedef unsigned WIDE_INT u_wide_int

Enumerations

enum  boolean_e { NO = 0, YES = 1 }
enum  length_modifier_e { LM_STD = 0, LM_SIZE_T, LM_LONG, LM_LONG_DOUBLE }

Functions

PHPAPI int ap_php_slprintf (char *buf, size_t len, const char *format,...)
PHPAPI int ap_php_vslprintf (char *buf, size_t len, const char *format, va_list ap)
PHPAPI int ap_php_snprintf (char *, size_t, const char *,...)
PHPAPI int ap_php_vsnprintf (char *, size_t, const char *, va_list ap)
PHPAPI int ap_php_vasprintf (char **buf, const char *format, va_list ap)
PHPAPI int ap_php_asprintf (char **buf, const char *format,...)
PHPAPI int php_sprintf (char *s, const char *format,...) PHP_ATTRIBUTE_FORMAT(printf
PHPAPI int PHPAPI char * php_gcvt (double value, int ndigit, char dec_point, char exponent, char *buf)
PHPAPI char * php_conv_fp (register char format, register double num, boolean_e add_dp, int precision, char dec_point, bool_int *is_negative, char *buf, int *len)
char * ap_php_conv_10 (register wide_int num, register bool_int is_unsigned, register bool_int *is_negative, char *buf_end, register int *len)
char * ap_php_conv_p2 (register u_wide_int num, register int nbits, char format, char *buf_end, register int *len)

Define Documentation

#define asprintf   ap_php_asprintf

Definition at line 119 of file snprintf.h.

#define FORMAT_CONV_MAX_PRECISION   500

Definition at line 170 of file snprintf.h.

#define slprintf   ap_php_slprintf

Definition at line 97 of file snprintf.h.

#define snprintf   ap_php_snprintf

Definition at line 107 of file snprintf.h.

#define sprintf   php_sprintf

Definition at line 125 of file snprintf.h.

Definition at line 115 of file snprintf.h.

Definition at line 102 of file snprintf.h.

Definition at line 112 of file snprintf.h.

#define WIDE_INT   long

Definition at line 150 of file snprintf.h.


Typedef Documentation

typedef int bool_int

Definition at line 73 of file snprintf.h.

typedef unsigned WIDE_INT u_wide_int

Definition at line 153 of file snprintf.h.

typedef WIDE_INT wide_int

Definition at line 152 of file snprintf.h.


Enumeration Type Documentation

enum boolean_e
Enumerator:
NO 
YES 

Definition at line 75 of file snprintf.h.

             {
       NO = 0, YES = 1
} boolean_e;
Enumerator:
LM_STD 
LM_SIZE_T 
LM_LONG 
LM_LONG_DOUBLE 

Definition at line 127 of file snprintf.h.

             {
       LM_STD = 0,
#if SIZEOF_INTMAX_T
       LM_INTMAX_T,
#endif
#if SIZEOF_PTRDIFF_T
       LM_PTRDIFF_T,
#endif
#if SIZEOF_LONG_LONG
       LM_LONG_LONG,
#endif
       LM_SIZE_T,
       LM_LONG,
       LM_LONG_DOUBLE
} length_modifier_e;

Function Documentation

PHPAPI int ap_php_asprintf ( char **  buf,
const char *  format,
  ... 
)

Definition at line 1297 of file snprintf.c.

{
       int cc;
       va_list ap;

       va_start(ap, format);
       cc = vasprintf(buf, format, ap);
       va_end(ap);
       return cc;
}
char* ap_php_conv_10 ( register wide_int  num,
register bool_int  is_unsigned,
register bool_int is_negative,
char *  buf_end,
register int len 
)

Definition at line 314 of file snprintf.c.

{
       register char *p = buf_end;
       register u_wide_int magnitude;

       if (is_unsigned) {
              magnitude = (u_wide_int) num;
              *is_negative = FALSE;
       } else {
              *is_negative = (num < 0);

              /*
               * On a 2's complement machine, negating the most negative integer
               * results in a number that cannot be represented as a signed integer.
               * Here is what we do to obtain the number's magnitude:
               *      a. add 1 to the number
               *      b. negate it (becomes positive)
               *      c. convert it to unsigned
               *      d. add 1
               */
              if (*is_negative) {
                     wide_int t = num + 1;
                     magnitude = ((u_wide_int) - t) + 1;
              } else {
                     magnitude = (u_wide_int) num;
              }
       }

       /*
        * We use a do-while loop so that we write at least 1 digit
        */
       do {
              register u_wide_int new_magnitude = magnitude / 10;

              *--p = (char)(magnitude - new_magnitude * 10 + '0');
              magnitude = new_magnitude;
       }
       while (magnitude);

       *len = buf_end - p;
       return (p);
}

Here is the caller graph for this function:

char* ap_php_conv_p2 ( register u_wide_int  num,
register int  nbits,
char  format,
char *  buf_end,
register int len 
)

Definition at line 477 of file snprintf.c.

{
       register int mask = (1 << nbits) - 1;
       register char *p = buf_end;
       static char low_digits[] = "0123456789abcdef";
       static char upper_digits[] = "0123456789ABCDEF";
       register char *digits = (format == 'X') ? upper_digits : low_digits;

       do {
              *--p = digits[num & mask];
              num >>= nbits;
       }
       while (num);

       *len = buf_end - p;
       return (p);
}

Here is the caller graph for this function:

PHPAPI int ap_php_slprintf ( char *  buf,
size_t  len,
const char *  format,
  ... 
)

Definition at line 1223 of file snprintf.c.

{
       int cc;
       va_list ap;

       va_start(ap, format);
       strx_printv(&cc, buf, len, format, ap);
       va_end(ap);
       if (cc >= len) {
              cc = len -1;
              buf[cc] = '\0';
       }
       return cc;
}

Here is the call graph for this function:

PHPAPI int ap_php_snprintf ( char *  ,
size_t  ,
const char *  ,
  ... 
)

Definition at line 1252 of file snprintf.c.

{
       int cc;
       va_list ap;

       va_start(ap, format);
       strx_printv(&cc, buf, len, format, ap);
       va_end(ap);
       return (cc);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PHPAPI int ap_php_vasprintf ( char **  buf,
const char *  format,
va_list  ap 
)

Definition at line 1273 of file snprintf.c.

{
       va_list ap2;
       int cc;

       va_copy(ap2, ap);
       cc = ap_php_vsnprintf(NULL, 0, format, ap2);
       va_end(ap2);

       *buf = NULL;

       if (cc >= 0) {
              if ((*buf = malloc(++cc)) != NULL) {
                     if ((cc = ap_php_vsnprintf(*buf, cc, format, ap)) < 0) {
                            free(*buf);
                            *buf = NULL;
                     }
              }
       }

       return cc;
}

Here is the call graph for this function:

PHPAPI int ap_php_vslprintf ( char *  buf,
size_t  len,
const char *  format,
va_list  ap 
)

Definition at line 1239 of file snprintf.c.

{
       int cc;

       strx_printv(&cc, buf, len, format, ap);
       if (cc >= len) {
              cc = len -1;
              buf[cc] = '\0';
       }
       return cc;
}

Here is the call graph for this function:

PHPAPI int ap_php_vsnprintf ( char *  ,
size_t  ,
const char *  ,
va_list  ap 
)

Definition at line 1264 of file snprintf.c.

{
       int cc;

       strx_printv(&cc, buf, len, format, ap);
       return (cc);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PHPAPI char* php_conv_fp ( register char  format,
register double  num,
boolean_e  add_dp,
int  precision,
char  dec_point,
bool_int is_negative,
char *  buf,
int len 
)

Definition at line 372 of file snprintf.c.

{
       register char *s = buf;
       register char *p, *p_orig;
       int decimal_point;

       if (precision >= NDIG - 1) {
              precision = NDIG - 2;
       }

       if (format == 'F') {
              p_orig = p = php_fcvt(num, precision, &decimal_point, is_negative);
       } else {                                         /* either e or E format */
              p_orig = p = php_ecvt(num, precision + 1, &decimal_point, is_negative);
       }

       /*
        * Check for Infinity and NaN
        */
       if (isalpha((int)*p)) {
              *len = strlen(p);
              memcpy(buf, p, *len + 1);
              *is_negative = FALSE;
              free(p_orig);
              return (buf);
       }
       if (format == 'F') {
              if (decimal_point <= 0) {
                     if (num != 0 || precision > 0) {
                            *s++ = '0';
                            if (precision > 0) {
                                   *s++ = dec_point;
                                   while (decimal_point++ < 0) {
                                          *s++ = '0';
                                   }
                            } else if (add_dp) {
                                   *s++ = dec_point;
                            }
                     }
              } else {
                     int addz = decimal_point >= NDIG ? decimal_point - NDIG + 1 : 0;
                     decimal_point -= addz;
                     while (decimal_point-- > 0) {
                            *s++ = *p++;
                     }
                     while (addz-- > 0) {
                            *s++ = '0';
                     }
                     if (precision > 0 || add_dp) {
                            *s++ = dec_point;
                     }
              }
       } else {
              *s++ = *p++;
              if (precision > 0 || add_dp) {
                     *s++ = '.';
              }
       }

       /*
        * copy the rest of p, the NUL is NOT copied
        */
       while (*p) {
              *s++ = *p++;
       }

       if (format != 'F') {
              char temp[EXPONENT_LENGTH];        /* for exponent conversion */
              int t_len;
              bool_int exponent_is_negative;

              *s++ = format;                     /* either e or E */
              decimal_point--;
              if (decimal_point != 0) {
                     p = ap_php_conv_10((wide_int) decimal_point, FALSE, &exponent_is_negative, &temp[EXPONENT_LENGTH], &t_len);
                     *s++ = exponent_is_negative ? '-' : '+';

                     /*
                      * Make sure the exponent has at least 2 digits
                      */
                     while (t_len--) {
                            *s++ = *p++;
                     }
              } else {
                     *s++ = '+';
                     *s++ = '0';
              }
       }
       *len = s - buf;
       free(p_orig);
       return (buf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PHPAPI int PHPAPI char* php_gcvt ( double  value,
int  ndigit,
char  dec_point,
char  exponent,
char *  buf 
)

Definition at line 137 of file snprintf.c.

{
       char *digits, *dst, *src;
       int i, decpt, sign;

       digits = zend_dtoa(value, 2, ndigit, &decpt, &sign, NULL);
       if (decpt == 9999) {
              /*
               * Infinity or NaN, convert to inf or nan with sign.
               * We assume the buffer is at least ndigit long.
               */
              snprintf(buf, ndigit + 1, "%s%s", (sign && *digits == 'I') ? "-" : "", *digits == 'I' ? "INF" : "NAN");
              zend_freedtoa(digits);
              return (buf);
       }

       dst = buf;
       if (sign) {
              *dst++ = '-';
       }

       if ((decpt >= 0 && decpt > ndigit) || decpt < -3) { /* use E-style */
              /* exponential format (e.g. 1.2345e+13) */
              if (--decpt < 0) {
                     sign = 1;
                     decpt = -decpt;
              } else {
                     sign = 0;
              }
              src = digits;
              *dst++ = *src++;
              *dst++ = dec_point;
              if (*src == '\0') {
                     *dst++ = '0';
              } else {
                     do {
                            *dst++ = *src++;
                     } while (*src != '\0');
              }
              *dst++ = exponent;
              if (sign) {
                     *dst++ = '-';
              } else {
                     *dst++ = '+';
              }
              if (decpt < 10) {
                     *dst++ = '0' + decpt;
                     *dst = '\0';
              } else {
                     /* XXX - optimize */
                     for (sign = decpt, i = 0; (sign /= 10) != 0; i++)
                            continue;
                     dst[i + 1] = '\0';
                     while (decpt != 0) {
                            dst[i--] = '0' + decpt % 10;
                            decpt /= 10;
                     }
              }
       } else if (decpt < 0) {
              /* standard format 0. */
              *dst++ = '0';   /* zero before decimal point */
              *dst++ = dec_point;
              do {
                     *dst++ = '0';
              } while (++decpt < 0);
              src = digits;
              while (*src != '\0') {
                     *dst++ = *src++;
              }
              *dst = '\0';
       } else {
              /* standard format */
              for (i = 0, src = digits; i < decpt; i++) {
                     if (*src != '\0') {
                            *dst++ = *src++;
                     } else {
                            *dst++ = '0';
                     }
              }
              if (*src != '\0') {
                     if (src == digits) {
                            *dst++ = '0';   /* zero before decimal point */
                     }
                     *dst++ = dec_point;
                     for (i = decpt; digits[i] != '\0'; i++) {
                *dst++ = digits[i];
            }
        }
        *dst = '\0';
    }
    zend_freedtoa(digits);
    return (buf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PHPAPI int php_sprintf ( char *  s,
const char *  format,
  ... 
)