About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

snprintf.c File Reference
#include "snprintf.h"
#include <stdlib.h>
Include dependency graph for snprintf.c:

Go to the source code of this file.


#define P_CONST   PTS_const
#define NULL   ((void*)0)
#define size_t   slen_t /* normally defined in <sys/types.h> */
#define sizeret_t   slen_t /* normally: int, unsigned */
#define NEED_SPRINTF   1
#define vsnprintf   fixup_vsnprintf
#define snprintf   fixup_snprintf
#define vasprintf   fixup_vasprintf
#define asprintf   fixup_asprintf
#define sprintf   fixup_sprintf
#define LDOUBLE   double
#define LLONG   long
#define DP_S_DEFAULT   0
#define DP_S_FLAGS   1
#define DP_S_MIN   2
#define DP_S_DOT   3
#define DP_S_MAX   4
#define DP_S_MOD   5
#define DP_S_CONV   6
#define DP_S_DONE   7
#define DP_F_MINUS   (1 << 0)
#define DP_F_PLUS   (1 << 1)
#define DP_F_SPACE   (1 << 2)
#define DP_F_NUM   (1 << 3)
#define DP_F_ZERO   (1 << 4)
#define DP_F_UP   (1 << 5)
#define DP_F_UNSIGNED   (1 << 6)
#define DP_C_SHORT   1
#define DP_C_LONG   2
#define DP_C_LDOUBLE   3
#define DP_C_LLONG   4
#define char_to_int(p)   ((p)- '0')
#define MAX(p, q)   (((p) >= (q)) ? (p) : (q))
#define isdigit(c)   ((unsigned char)((c)-'0')<=(unsigned char)('9'-'0'))


typedef slen_t ret_t


slen_t fixup_vsnprintf (char *str, slen_t count, const char *fmt, va_list args)
slen_t fixup_snprintf (char *str, slen_t count, const char *fmt,...)
slen_t fixup_vasprintf (char **ptr, const char *format, va_list ap)
slen_t fixup_asprintf (char **ptr, const char *format,...)
slen_t fixup_sprintf (char *ptr, const char *format,...)
static slen_t dopr (char *buffer, slen_t maxlen, const char *format, va_list args)
static void fmtstr (char *buffer, slen_t *currlen, slen_t maxlen, char *value, int flags, int min, int max)
static void fmtint (char *buffer, slen_t *currlen, slen_t maxlen, long value, int base, int min, int max, int flags)
static void fmtfp (char *buffer, slen_t *currlen, slen_t maxlen, double fvalue, int min, int max, int flags)
static void dopr_outch (char *buffer, slen_t *currlen, slen_t maxlen, char c)
static double abs_val (double value)
static double POW10 (int exp)
static long ROUND (double value)
static double my_modf (double x0, double *iptr)

Macro Definition Documentation

◆ asprintf

#define asprintf   fixup_asprintf

Definition at line 43 of file snprintf.c.

◆ char_to_int

#define char_to_int (   p)    ((p)- '0')

Definition at line 170 of file snprintf.c.


#define DP_C_LDOUBLE   3

Definition at line 167 of file snprintf.c.


#define DP_C_LLONG   4

Definition at line 168 of file snprintf.c.


#define DP_C_LONG   2

Definition at line 166 of file snprintf.c.


#define DP_C_SHORT   1

Definition at line 165 of file snprintf.c.


#define DP_F_MINUS   (1 << 0)

Definition at line 156 of file snprintf.c.


#define DP_F_NUM   (1 << 3)

Definition at line 159 of file snprintf.c.


#define DP_F_PLUS   (1 << 1)

Definition at line 157 of file snprintf.c.


#define DP_F_SPACE   (1 << 2)

Definition at line 158 of file snprintf.c.


#define DP_F_UNSIGNED   (1 << 6)

Definition at line 162 of file snprintf.c.


#define DP_F_UP   (1 << 5)

Definition at line 161 of file snprintf.c.


#define DP_F_ZERO   (1 << 4)

Definition at line 160 of file snprintf.c.


#define DP_S_CONV   6

Definition at line 152 of file snprintf.c.


#define DP_S_DEFAULT   0

Definition at line 146 of file snprintf.c.


#define DP_S_DONE   7

Definition at line 153 of file snprintf.c.


#define DP_S_DOT   3

Definition at line 149 of file snprintf.c.


#define DP_S_FLAGS   1

Definition at line 147 of file snprintf.c.


#define DP_S_MAX   4

Definition at line 150 of file snprintf.c.


#define DP_S_MIN   2

Definition at line 148 of file snprintf.c.


#define DP_S_MOD   5

Definition at line 151 of file snprintf.c.

◆ isdigit

#define isdigit (   c)    ((unsigned char)((c)-'0')<=(unsigned char)('9'-'0'))

Definition at line 177 of file snprintf.c.


#define LDOUBLE   double

Original: Patrick Powell Tue Apr 11 09:48:21 PDT 1995 A bombproof version of doprnt (dopr) included. Sigh. This sort of thing is always nasty do deal with. Note that the version here does not include floating point...

snprintf() is used instead of sprintf() as it does limit checks for string length. This covers a nasty loophole.

The other functions are there to prevent NULL pointers from causing nast effects.

More Recently: Brandon Long blong.nosp@m.@fic.nosp@m.tion..nosp@m.net 9/15/96 for mutt 0.43 This was ugly. It is still ugly. I opted out of floating point numbers, but the formatter understands just about everything from the normal C string format, at least as far as I can tell from the Solaris 2.5 printf(3S) man page.

Brandon Long blong.nosp@m.@fic.nosp@m.tion..nosp@m.net 10/22/97 for mutt 0.87.1 Ok, added some minimal floating point support, which means this probably requires libm on most operating systems. Don't yet support the exponent (e,E) and sigfig (g,G). Also, fmtint() was pretty badly broken, it just wasn't being exercised in ways which showed it, so that's been fixed. Also, formated the code to mutt conventions, and removed dead code left over from the original. Also, there is now a builtin-test, just compile with: gcc -DTEST_SNPRINTF -o snprintf snprintf.c -lm and run snprintf for results.

Thomas Roessler roess.nosp@m.ler@.nosp@m.guug..nosp@m.de 01/27/98 for mutt 0.89i The PGP code was using unsigned hexadecimal formats. Unfortunately, unsigned formats simply didn't work.

Michael Elkins me@cs.nosp@m..hmc.nosp@m..edu 03/05/98 for mutt 0.90.8 The original code assumed that both snprintf() and vsnprintf() were missing. Some systems only have snprintf() but not vsnprintf(), so the code is now broken down under HAVE_SNPRINTF and HAVE_VSNPRINTF.

Andrew Tridgell (tridg.nosp@m.e@sa.nosp@m.mba.o.nosp@m.rg) Oct 1998 fixed handling of %.0f added test for HAVE_LONG_DOUBLE

tridg.nosp@m.e@sa.nosp@m.mba.o.nosp@m.rg, idra@.nosp@m.samb.nosp@m.a.org, April 2001 got rid of fcvt code (twas buggy and made testing harder) added C99 semantics

Definition at line 122 of file snprintf.c.


#define LLONG   long

Definition at line 128 of file snprintf.c.


#define MAX (   p,
)    (((p) >= (q)) ? (p) : (q))

Definition at line 172 of file snprintf.c.


#define NEED_SPRINTF   1

Definition at line 39 of file snprintf.c.


#define NULL   ((void*)0)

Definition at line 24 of file snprintf.c.


#define P_CONST   PTS_const

Definition at line 20 of file snprintf.c.

◆ size_t

#define size_t   slen_t /* normally defined in <sys/types.h> */

Definition at line 30 of file snprintf.c.

◆ sizeret_t

#define sizeret_t   slen_t /* normally: int, unsigned */

Definition at line 31 of file snprintf.c.

◆ snprintf

#define snprintf   fixup_snprintf

Definition at line 41 of file snprintf.c.

◆ sprintf

#define sprintf   fixup_sprintf

Definition at line 44 of file snprintf.c.

◆ vasprintf

#define vasprintf   fixup_vasprintf

Definition at line 42 of file snprintf.c.

◆ vsnprintf

#define vsnprintf   fixup_vsnprintf

Definition at line 40 of file snprintf.c.

Typedef Documentation

◆ ret_t

typedef slen_t ret_t

Definition at line 45 of file snprintf.c.

Function Documentation

◆ abs_val()

static double abs_val ( double  value)

Definition at line 559 of file snprintf.c.

References LDOUBLE, and check-static-inits::result.

Referenced by fmtfp().

◆ dopr()

◆ dopr_outch()

static void dopr_outch ( char *  buffer,
slen_t currlen,
slen_t  maxlen,
char  c 

Definition at line 782 of file snprintf.c.

References c.

Referenced by dopr(), fmtfp(), fmtint(), and fmtstr().

◆ fixup_asprintf()

slen_t fixup_asprintf ( char **  ptr,
const char *  format,

Definition at line 829 of file snprintf.c.

References ap, format, ptr, PTS_va_start, ret, sizeret_t, va_end, and vasprintf.

◆ fixup_snprintf()

slen_t fixup_snprintf ( char *  str,
slen_t  count,
const char *  fmt,

Definition at line 798 of file snprintf.c.

References ap, count, fmt, PTS_va_start, ret, str, va_end, and vsnprintf.

◆ fixup_sprintf()

slen_t fixup_sprintf ( char *  ptr,
const char *  format,

Definition at line 844 of file snprintf.c.

References ap, format, NULL, ptr, PTS_va_start, ret, sizeret_t, va_end, and vsnprintf.

◆ fixup_vasprintf()

slen_t fixup_vasprintf ( char **  ptr,
const char *  format,
va_list  ap 

Definition at line 813 of file snprintf.c.

References ap, format, malloc, NULL, NULLP, ptr, ret, sizeret_t, and vsnprintf.

◆ fixup_vsnprintf()

slen_t fixup_vsnprintf ( char *  str,
slen_t  count,
const char *  fmt,
va_list  args 

Definition at line 791 of file snprintf.c.

References count, dopr(), fmt, and str.

◆ fmtfp()

static void fmtfp ( char *  buffer,
slen_t currlen,
slen_t  maxlen,
double  fvalue,
int  min,
int  max,
int  flags 

◆ fmtint()

static void fmtint ( char *  buffer,
slen_t currlen,
slen_t  maxlen,
long  value,
int  base,
int  min,
int  max,
int  flags 

Definition at line 475 of file snprintf.c.

References base, caps, convert, dopr_outch(), DP_F_MINUS, DP_F_PLUS, DP_F_SPACE, DP_F_UNSIGNED, DP_F_UP, DP_F_ZERO, flags, max, MAX, min, printf(), and uvalue.

Referenced by dopr().

◆ fmtstr()

static void fmtstr ( char *  buffer,
slen_t currlen,
slen_t  maxlen,
char *  value,
int  flags,
int  min,
int  max 

Definition at line 437 of file snprintf.c.

References cnt, dopr_outch(), DP_F_MINUS, flags, max, min, and printf().

Referenced by dopr().

◆ my_modf()

static double my_modf ( double  x0,
double *  iptr 

Definition at line 594 of file snprintf.c.

References f, i, cutout::l, ret, cordic::x, and x0.

Referenced by fmtfp().

◆ POW10()

static double POW10 ( int  exp)

Definition at line 569 of file snprintf.c.

References exp(), LDOUBLE, and check-static-inits::result.

Referenced by fmtfp().


static long ROUND ( double  value)

Definition at line 581 of file snprintf.c.

References LLONG.

Referenced by fmtfp().