Pip
Architecture-dependent parts of Pip: MAL, IAL and boot
Data Structures | Macros | Typedefs | Functions
printf.c File Reference
#include <stdbool.h>
#include <stdint.h>
#include "printf.h"

Data Structures

struct  out_fct_wrap_type
 

Macros

#define PRINTF_NTOA_BUFFER_SIZE   32U
 
#define PRINTF_FTOA_BUFFER_SIZE   32U
 
#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_WIDTH   (1U << 11U)
 

Typedefs

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

Functions

static void _out_buffer (char character, char *buffer, size_t idx, size_t maxlen)
 
static void _out_null (char character, char *buffer, size_t idx, size_t maxlen)
 
static void _out_char (char character, char *buffer, size_t idx, size_t maxlen)
 
static void _out_fct (char character, char *buffer, size_t idx, size_t maxlen)
 
static unsigned int _strlen (const char *str)
 
static bool _is_digit (char ch)
 
static unsigned int _atoi (const char **str)
 
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 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 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,...)
 

Macro Definition Documentation

◆ FLAGS_CHAR

#define FLAGS_CHAR   (1U << 6U)

◆ FLAGS_HASH

#define FLAGS_HASH   (1U << 4U)

◆ FLAGS_LEFT

#define FLAGS_LEFT   (1U << 1U)

◆ FLAGS_LONG

#define FLAGS_LONG   (1U << 8U)

◆ FLAGS_LONG_LONG

#define FLAGS_LONG_LONG   (1U << 9U)

◆ FLAGS_PLUS

#define FLAGS_PLUS   (1U << 2U)

◆ FLAGS_PRECISION

#define FLAGS_PRECISION   (1U << 10U)

◆ FLAGS_SHORT

#define FLAGS_SHORT   (1U << 7U)

◆ FLAGS_SPACE

#define FLAGS_SPACE   (1U << 3U)

◆ FLAGS_UPPERCASE

#define FLAGS_UPPERCASE   (1U << 5U)

◆ FLAGS_WIDTH

#define FLAGS_WIDTH   (1U << 11U)

◆ FLAGS_ZEROPAD

#define FLAGS_ZEROPAD   (1U << 0U)

◆ PRINTF_FTOA_BUFFER_SIZE

#define PRINTF_FTOA_BUFFER_SIZE   32U

◆ PRINTF_NTOA_BUFFER_SIZE

#define PRINTF_NTOA_BUFFER_SIZE   32U

◆ PRINTF_SUPPORT_PTRDIFF_T

#define PRINTF_SUPPORT_PTRDIFF_T

Typedef Documentation

◆ out_fct_type

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

Function Documentation

◆ _atoi()

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

◆ _is_digit()

static bool _is_digit ( char  ch)
inlinestatic

◆ _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

◆ _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

◆ _out_buffer()

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

◆ _out_char()

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

◆ _out_fct()

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

◆ _out_null()

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

◆ _strlen()

static unsigned int _strlen ( const char *  str)
inlinestatic

◆ _vsnprintf()

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

◆ 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

◆ printf()

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

Tiny printf implementation You have to implement _putchar if you use printf()

Parameters
formatA string that specifies the format of the output
Returns
The number of characters that are written into the array, not counting the terminating null character

◆ snprintf()

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

Tiny snprintf/vsnprintf implementation

Parameters
bufferA pointer to the buffer where to store the formatted string
countThe maximum number of characters to store in the buffer, including a terminating null character
formatA string that specifies the format of the output
Returns
The number of characters that are WRITTEN into the buffer, not counting the terminating null character If the formatted string is truncated the buffer size (count) is returned

◆ sprintf()

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

Tiny sprintf implementation Due to security reasons (buffer overflow) YOU SHOULD CONSIDER USING (V)SNPRINTF INSTEAD!

Parameters
bufferA pointer to the buffer where to store the formatted string. MUST be big enough to store the output!
formatA string that specifies the format of the output
Returns
The number of characters that are WRITTEN into the buffer, not counting the terminating null character

◆ vsnprintf()

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