fmt − ASCII representation of strings and integers
#include "fmt.h"
unsigned int
fmt_str(char *dest,const char *source);
unsigned int fmt_strn(char *dest,const char
*source,unsigned int maxlen);
unsigned int
fmt_uint(char *dest,unsigned int
source);
unsigned int fmt_uint0(char *dest,unsigned int
source,unsigned int n);
unsigned int fmt_ulong(char *dest,unsigned
long source);
unsigned int fmt_xlong(char *dest,unsigned
long source);
char tohex(char num);
int fromhex(unsigned char c);
fmt_str copies all leading nonzero bytes from source to dest and returns the number of bytes it copied. fmt_str does not append \0.
fmt_strn copies at most maxlen leading nonzero bytes from source to dest and returns the number of bytes it copied. fmt_strn does not append \0.
fmt_uint writes an ASCII representation (’0’ to ’9’, base 10) of source to dest and returns the number of bytes written. fmt_uint does not append \0.
fmt_uint0 writes an ASCII representation (’0’ to ’9’, base 10) of source to dest and returns the number of bytes written. The output is padded with ’0’-bytes until it encompasses at least n bytes, but it will not be truncated if it does not fit. fmt_uint0 does not append \0.
fmt_ulong writes an ASCII representation (’0’ to ’9’, base 10) of source to dest and returns the number of bytes written perhaps including a trailing \0. fmt_ulong does not append \0.
fmt_xlong writes an ASCII representation (’0’ to ’9’ and ’a’ to ’f’, base 16) of source to dest and returns the number of bytes written. fmt_xlong does not append \0.
tohex reads the ASCII representation of a decimal num and returns its hexadecimal ASCII value; thus ´0´ -> ´0´ ... ´9´ -> ´9´, ´10´ -> ´a´ and finally ´15´ -> f’.
fromhex reads the ACSII representation of a hexadecimal number ´0´ to ´f´ irrelevant of its case and returns its integer value.
For convenience, fmt.h defines the integers FMT_LEN and FMT_ULONG to be big enough to the number of bytes it would have written.
For the functions fmt_uint and fmt_ulong you may use the _GENERIC makro fmt_dnum.
If dest equals FMT_LEN (i.e. is zero), all fmt_* routins return the number of bytes it would have written i.e. the number of leading nonzero bytes of source perhaps including a \0.
byte(3), case(3), scan(3)