qlibs:(fmt)

πŸ“¦ version 31, in alpine 3.24

✨ NAME ✨

okay so this is the qlibs:(fmt) manual page, and fmt is literally the whole β€œASCII representation of strings and integers” situation β€” bestie, it’s giving low-level string-and-number realness πŸ’–

πŸ› οΈ SYNTAX πŸ› οΈ

#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);

πŸ’… DESCRIPTION πŸ’…

  • fmt_str β€” copies all the leading nonzero bytes from source to dest, then returns the number of bytes it copied. It does not append \0, bestie.
  • fmt_strn β€” copies at most maxlen leading nonzero bytes from source to dest, then returns the number of bytes it copied. It does not append \0 either.
  • fmt_uint β€” writes an ASCII representation ('0' to '9', base 10) of source to dest, then 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, then 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, then returns the number of bytes written, perhaps including a trailing \0. fmt_ulong does not append \0.
⚠️ yes, the page literally says β€œperhaps including a trailing \0” and then β€œdoes not append \0” β€” I’m not fixing the wording, I’m just reporting the tea πŸ’€
  • fmt_xlong β€” writes an ASCII representation ('0' to '9' and 'a' to 'f', base 16) of source to dest, then 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'. iconic little mapping, no cap.
  • fromhex β€” reads the ACSII representation of a hexadecimal number Β΄0Β΄ to Β΄fΒ΄, irrelevant of its case, and returns its integer value. (yes, ACSII β€” that’s what the page says 🫢)

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.

🧚 GENERICS 🧚

For the functions fmt_uint and fmt_ulong you may use the _GENERIC makro fmt_dnum. yes, it says makro β€” we move πŸ’…

πŸŽ€ RETURN CODES πŸŽ€

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. that’s the whole return-code vibe, bestie ✨

πŸ¦‹ SEE ALSO πŸ¦‹

byte(3), case(3), scan(3)


✨ cute sign-off: this was the qlibs:(fmt) page, footer says 3 and qlibs:(fmt), and there’s no date printed down there β€” so consider this your official group-chat goodbye. stay slay, may your buffers behave, and hydrate before touching pointers πŸ’…πŸ«ΆπŸŒˆ

πŸ“¦ where this page comes from