MentOS  0.8.0
The Mentoring Operating System
Macros | Functions | Variables
vsprintf.c File Reference

Print formatting routines. More...

Macros

#define CVTBUFSIZE   500
 Size of the buffer used to call cvt functions.
 
#define FLAGS_ZEROPAD   (1U << 0U)
 Fill zeros before the number.
 
#define FLAGS_LEFT   (1U << 1U)
 Left align the value.
 
#define FLAGS_PLUS   (1U << 2U)
 Print the plus sign.
 
#define FLAGS_SPACE   (1U << 3U)
 If positive add a space instead of the plus sign.
 
#define FLAGS_HASH   (1U << 4U)
 Preceed with 0x or 0X, x or X respectively.
 
#define FLAGS_UPPERCASE   (1U << 5U)
 Print uppercase.
 
#define FLAGS_SIGN   (1U << 6U)
 Print the sign.
 

Functions

static int skip_atoi (const char **s)
 Returns the index of the first non-integer character. More...
 
static char * number (char *str, long num, int base, int size, int32_t precision, unsigned flags)
 Places the number inside the string. More...
 
static char * eaddr (char *str, unsigned char *addr, int size, int precision, unsigned flags)
 Prints a MAC address. More...
 
static char * iaddr (char *str, unsigned char *addr, int size, int precision, unsigned flags)
 Prints an internet address. More...
 
static void cfltcvt (double value, char *buffer, char fmt, int precision)
 Prints a floating point value. More...
 
static void forcdecpt (char *buffer)
 Should we force the decimal point. More...
 
static void cropzeros (char *buffer)
 Crop zero unless '#' given. More...
 
static char * flt (char *str, double num, int size, int precision, char fmt, unsigned flags)
 Transforms a floating point value to string. More...
 
int vsprintf (char *str, const char *fmt, va_list args)
 Write formatted data from variable argument list to string. More...
 
int printf (const char *format,...)
 Write formatted output to stdout. More...
 
int sprintf (char *str, const char *fmt,...)
 Write formatted output to str. More...
 

Variables

static char * _digits = "0123456789abcdefghijklmnopqrstuvwxyz"
 The list of digits.
 
static char * _upper_digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
 The list of uppercase digits.
 

Detailed Description

Print formatting routines.

Function Documentation

◆ cfltcvt()

static void cfltcvt ( double  value,
char *  buffer,
char  fmt,
int  precision 
)
static

Prints a floating point value.

Parameters
valuethe value to print.
bufferthe buffer where the value is stored.
fmtthe format.
precisionthe precision.

◆ cropzeros()

static void cropzeros ( char *  buffer)
static

Crop zero unless '#' given.

Parameters
bufferthe buffer to work on.

◆ eaddr()

static char* eaddr ( char *  str,
unsigned char *  addr,
int  size,
int  precision,
unsigned  flags 
)
static

Prints a MAC address.

Parameters
strthe string where we store the address.
addrthe address we need to store.
sizethe size available in str.
precisionthe precision to use.
flagssupport flags.
Returns
a pointer to str itself, or NULL.

◆ flt()

static char* flt ( char *  str,
double  num,
int  size,
int  precision,
char  fmt,
unsigned  flags 
)
static

Transforms a floating point value to string.

Parameters
strthe string where the floating point value should be stored.
numthe number to store.
sizethe size available for storing the floating point value.
precisionthe precision.
fmtthe format.
flagsthe support flags.
Returns
a pointer to str itself.

◆ forcdecpt()

static void forcdecpt ( char *  buffer)
static

Should we force the decimal point.

Parameters
bufferthe buffer where we force the decimal point.

◆ iaddr()

static char* iaddr ( char *  str,
unsigned char *  addr,
int  size,
int  precision,
unsigned  flags 
)
static

Prints an internet address.

Parameters
strthe string where we store the address.
addrthe address we need to store.
sizethe size available in str.
precisionthe precision to use.
flagssupport flags.
Returns
a pointer to str itself, or NULL.

◆ number()

static char* number ( char *  str,
long  num,
int  base,
int  size,
int32_t  precision,
unsigned  flags 
)
static

Places the number inside the string.

Parameters
strthe string where the number will end up in.
numthe number.
basethe base used to transform the number.
sizethe size available for storing the number.
precisionthe precision.
flagssupport flags.
Returns
the string itself, or NULL.

◆ printf()

int printf ( const char *  fmt,
  ... 
)

Write formatted output to stdout.

Parameters
fmtThe format string.
...The list of arguments.
Returns
On success, the total number of characters written is returned. On failure, a negative number is returned.

◆ skip_atoi()

static int skip_atoi ( const char **  s)
inlinestatic

Returns the index of the first non-integer character.

Parameters
sthe string.
Returns
the index of the first non-integer character.

◆ sprintf()

int sprintf ( char *  str,
const char *  fmt,
  ... 
)

Write formatted output to str.

Parameters
strThe buffer where the formatted string will be placed.
fmtFormat string, following the same specifications as printf.
...The list of arguments.
Returns
On success, the total number of characters written is returned. On failure, a negative number is returned.

◆ vsprintf()

int vsprintf ( char *  str,
const char *  fmt,
va_list  args 
)

Write formatted data from variable argument list to string.

Parameters
strPointer to a buffer where the resulting C-string is stored.
fmtFormat string, following the same specifications as printf.
argsA variable arguments list.
Returns
On success, the total number of characters written is returned. On failure, a negative number is returned.