printf.c File Reference
#include <stdbool.h>
#include <stdint.h>
#include "printf.h"
#include <float.h>

Go to the source code of this file.

Data Structures

struct  out_fct_wrap_type
 

Macros

#define PRINTF_NTOA_BUFFER_SIZE   32U
 
#define PRINTF_FTOA_BUFFER_SIZE   32U
 
#define PRINTF_SUPPORT_FLOAT
 
#define PRINTF_SUPPORT_EXPONENTIAL
 
#define PRINTF_DEFAULT_FLOAT_PRECISION   6U
 
#define PRINTF_MAX_FLOAT   1e9
 
#define PRINTF_SUPPORT_LONG_LONG
 
#define PRINTF_SUPPORT_PTRDIFF_T
 
#define FLAGS_ZEROPAD   (1U << 0U)
 
#define FLAGS_LEFT   (1U << 1U)
 
#define FLAGS_PLUS   (1U << 2U)
 
#define FLAGS_SPACE   (1U << 3U)
 
#define FLAGS_HASH   (1U << 4U)
 
#define FLAGS_UPPERCASE   (1U << 5U)
 
#define FLAGS_CHAR   (1U << 6U)
 
#define FLAGS_SHORT   (1U << 7U)
 
#define FLAGS_LONG   (1U << 8U)
 
#define FLAGS_LONG_LONG   (1U << 9U)
 
#define FLAGS_PRECISION   (1U << 10U)
 
#define FLAGS_ADAPT_EXP   (1U << 11U)
 

Typedefs

typedef void(* out_fct_type) (char character, void *buffer, size_t idx, size_t maxlen)
 

Functions

static void _out_buffer (char character, void *buffer, size_t idx, size_t maxlen)
 
static void _out_null (char character, void *buffer, size_t idx, size_t maxlen)
 
static void _out_char (char character, void *buffer, size_t idx, size_t maxlen)
 
static void _out_fct (char character, void *buffer, size_t idx, size_t maxlen)
 
static unsigned int _strnlen_s (const char *str, size_t maxsize)
 
static bool _is_digit (char ch)
 
static unsigned int _atoi (const char **str)
 
static size_t _out_rev (out_fct_type out, char *buffer, size_t idx, size_t maxlen, const char *buf, size_t len, unsigned int width, unsigned int flags)
 
static size_t _ntoa_format (out_fct_type out, char *buffer, size_t idx, size_t maxlen, char *buf, size_t len, bool negative, unsigned int base, unsigned int prec, unsigned int width, unsigned int flags)
 
static size_t _ntoa_long (out_fct_type out, char *buffer, size_t idx, size_t maxlen, unsigned long value, bool negative, unsigned long base, unsigned int prec, unsigned int width, unsigned int flags)
 
static size_t _ntoa_long_long (out_fct_type out, char *buffer, size_t idx, size_t maxlen, unsigned long long value, bool negative, unsigned long long base, unsigned int prec, unsigned int width, unsigned int flags)
 
static size_t _etoa (out_fct_type out, char *buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width, unsigned int flags)
 
static size_t _ftoa (out_fct_type out, char *buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width, unsigned int flags)
 
static int _vsnprintf (out_fct_type out, char *buffer, const size_t maxlen, const char *format, va_list va)
 
int printf_ (const char *format,...)
 
int sprintf_ (char *buffer, const char *format,...)
 
int snprintf_ (char *buffer, size_t count, const char *format,...)
 
int vprintf_ (const char *format, va_list va)
 
int vsnprintf_ (char *buffer, size_t count, const char *format, va_list va)
 
int fctprintf (void(*out)(char character, void *arg), void *arg, const char *format,...)
 
int fctvprintf (void(*out)(char character, void *arg), void *arg, const char *format, va_list va)
 

Macro Definition Documentation

◆ FLAGS_ADAPT_EXP

#define FLAGS_ADAPT_EXP   (1U << 11U)

Definition at line 112 of file printf.c.

◆ FLAGS_CHAR

#define FLAGS_CHAR   (1U << 6U)

Definition at line 107 of file printf.c.

◆ FLAGS_HASH

#define FLAGS_HASH   (1U << 4U)

Definition at line 105 of file printf.c.

◆ FLAGS_LEFT

#define FLAGS_LEFT   (1U << 1U)

Definition at line 102 of file printf.c.

◆ FLAGS_LONG

#define FLAGS_LONG   (1U << 8U)

Definition at line 109 of file printf.c.

◆ FLAGS_LONG_LONG

#define FLAGS_LONG_LONG   (1U << 9U)

Definition at line 110 of file printf.c.

◆ FLAGS_PLUS

#define FLAGS_PLUS   (1U << 2U)

Definition at line 103 of file printf.c.

◆ FLAGS_PRECISION

#define FLAGS_PRECISION   (1U << 10U)

Definition at line 111 of file printf.c.

◆ FLAGS_SHORT

#define FLAGS_SHORT   (1U << 7U)

Definition at line 108 of file printf.c.

◆ FLAGS_SPACE

#define FLAGS_SPACE   (1U << 3U)

Definition at line 104 of file printf.c.

◆ FLAGS_UPPERCASE

#define FLAGS_UPPERCASE   (1U << 5U)

Definition at line 106 of file printf.c.

◆ FLAGS_ZEROPAD

#define FLAGS_ZEROPAD   (1U << 0U)

Definition at line 101 of file printf.c.

◆ PRINTF_DEFAULT_FLOAT_PRECISION

#define PRINTF_DEFAULT_FLOAT_PRECISION   6U

Definition at line 76 of file printf.c.

◆ PRINTF_FTOA_BUFFER_SIZE

#define PRINTF_FTOA_BUFFER_SIZE   32U

Definition at line 58 of file printf.c.

◆ PRINTF_MAX_FLOAT

#define PRINTF_MAX_FLOAT   1e9

Definition at line 82 of file printf.c.

◆ PRINTF_NTOA_BUFFER_SIZE

#define PRINTF_NTOA_BUFFER_SIZE   32U

Definition at line 51 of file printf.c.

◆ PRINTF_SUPPORT_EXPONENTIAL

#define PRINTF_SUPPORT_EXPONENTIAL

Definition at line 70 of file printf.c.

◆ PRINTF_SUPPORT_FLOAT

#define PRINTF_SUPPORT_FLOAT

Definition at line 64 of file printf.c.

◆ PRINTF_SUPPORT_LONG_LONG

#define PRINTF_SUPPORT_LONG_LONG

Definition at line 88 of file printf.c.

◆ PRINTF_SUPPORT_PTRDIFF_T

#define PRINTF_SUPPORT_PTRDIFF_T

Definition at line 95 of file printf.c.

Typedef Documentation

◆ out_fct_type

typedef void(* out_fct_type) (char character, void *buffer, size_t idx, size_t maxlen)

Definition at line 121 of file printf.c.

Function Documentation

◆ _atoi()

static unsigned int _atoi ( const char **  str)
static

Definition at line 187 of file printf.c.

◆ _etoa()

static size_t _etoa ( out_fct_type  out,
char *  buffer,
size_t  idx,
size_t  maxlen,
double  value,
unsigned int  prec,
unsigned int  width,
unsigned int  flags 
)
static

Definition at line 466 of file printf.c.

◆ _ftoa()

static size_t _ftoa ( out_fct_type  out,
char *  buffer,
size_t  idx,
size_t  maxlen,
double  value,
unsigned int  prec,
unsigned int  width,
unsigned int  flags 
)
static

Definition at line 338 of file printf.c.

◆ _is_digit()

static bool _is_digit ( char  ch)
inlinestatic

Definition at line 180 of file printf.c.

◆ _ntoa_format()

static size_t _ntoa_format ( out_fct_type  out,
char *  buffer,
size_t  idx,
size_t  maxlen,
char *  buf,
size_t  len,
bool  negative,
unsigned int  base,
unsigned int  prec,
unsigned int  width,
unsigned int  flags 
)
static

Definition at line 226 of file printf.c.

◆ _ntoa_long()

static size_t _ntoa_long ( out_fct_type  out,
char *  buffer,
size_t  idx,
size_t  maxlen,
unsigned long  value,
bool  negative,
unsigned long  base,
unsigned int  prec,
unsigned int  width,
unsigned int  flags 
)
static

Definition at line 280 of file printf.c.

◆ _ntoa_long_long()

static size_t _ntoa_long_long ( out_fct_type  out,
char *  buffer,
size_t  idx,
size_t  maxlen,
unsigned long long  value,
bool  negative,
unsigned long long  base,
unsigned int  prec,
unsigned int  width,
unsigned int  flags 
)
static

Definition at line 305 of file printf.c.

◆ _out_buffer()

static void _out_buffer ( char  character,
void *  buffer,
size_t  idx,
size_t  maxlen 
)
inlinestatic

Definition at line 132 of file printf.c.

◆ _out_char()

static void _out_char ( char  character,
void *  buffer,
size_t  idx,
size_t  maxlen 
)
inlinestatic

Definition at line 148 of file printf.c.

◆ _out_fct()

static void _out_fct ( char  character,
void *  buffer,
size_t  idx,
size_t  maxlen 
)
inlinestatic

Definition at line 158 of file printf.c.

◆ _out_null()

static void _out_null ( char  character,
void *  buffer,
size_t  idx,
size_t  maxlen 
)
inlinestatic

Definition at line 141 of file printf.c.

◆ _out_rev()

static size_t _out_rev ( out_fct_type  out,
char *  buffer,
size_t  idx,
size_t  maxlen,
const char *  buf,
size_t  len,
unsigned int  width,
unsigned int  flags 
)
static

Definition at line 198 of file printf.c.

◆ _strnlen_s()

static unsigned int _strnlen_s ( const char *  str,
size_t  maxsize 
)
inlinestatic

Definition at line 170 of file printf.c.

◆ _vsnprintf()

static int _vsnprintf ( out_fct_type  out,
char *  buffer,
const size_t  maxlen,
const char *  format,
va_list  va 
)
static

Definition at line 576 of file printf.c.

◆ fctprintf()

int fctprintf ( void(*)(char character, void *arg)  out,
void *  arg,
const char *  format,
  ... 
)

printf with output function You may use this as dynamic alternative to printf() with its fixed _putchar() output

Parameters
outAn output function which takes one character and an argument pointer
argAn argument pointer for user data passed to output function
formatA string that specifies the format of the output
Returns
The number of characters that are sent to the output function, not counting the terminating null character

Definition at line 905 of file printf.c.

◆ fctvprintf()

int fctvprintf ( void(*)(char character, void *arg)  out,
void *  arg,
const char *  format,
va_list  va 
)

vprintf with output function You may use this as dynamic alternative to vprintf() with its fixed _putchar() output

Parameters
outAn output function which takes one character and an argument pointer
argAn argument pointer for user data passed to output function
formatA string that specifies the format of the output
vaA value identifying a variable arguments list
Returns
The number of characters that are sent to the output function, not counting the terminating null character

Definition at line 915 of file printf.c.

◆ printf_()

int printf_ ( const char *  format,
  ... 
)

Definition at line 861 of file printf.c.

◆ snprintf_()

int snprintf_ ( char *  buffer,
size_t  count,
const char *  format,
  ... 
)

Definition at line 882 of file printf.c.

◆ sprintf_()

int sprintf_ ( char *  buffer,
const char *  format,
  ... 
)

Definition at line 872 of file printf.c.

◆ vprintf_()

int vprintf_ ( const char *  format,
va_list  va 
)

Definition at line 892 of file printf.c.

◆ vsnprintf_()

int vsnprintf_ ( char *  buffer,
size_t  count,
const char *  format,
va_list  va 
)

Definition at line 899 of file printf.c.