SOLDOUT_BUFFER(3)

πŸ’– SOLDOUT_BUFFER πŸ’–

okay bestie, gather round 🫢 this is SOLDOUT_BUFFER(3) from the Library Functions Manual β€” literally the entire buffer-handling situation for soldout. it's giving "my strings need somewhere cute to live" and honestly? it ate. no cap. πŸ’…


✨ NAME ✨

soldout_buffer, bufcasecmp, bufcmp, bufcmps, bufdup, bufgrow, bufnew, bufnullterm, bufprintf, bufput, bufputs, bufputc, bufrelease, bufreset, bufset, bufslurp, buftoi, vbufprintf β€” buffer handling functions for soldout 🌸


πŸŽ€ SYNOPSIS πŸŽ€

#include <buffer.h>

#define CONST_BUF(name, string)
#define VOLATILE_BUF(name, strname)
#define BUFPUTSL(output, literal)

int
bufcasecmp(const struct buf *a, const struct buf *b);

int
bufcmp(const struct buf *a, const struct buf *b);

int
bufcmps(const struct buf *a, const char *b);

struct buf *
bufdup(const struct buf *src, size_t dupunit);

int
bufgrow(struct buf *buf, size_t sz);

struct buf *
bufnew(size_t unit);

void
bufnullterm(struct buf *buf);

void
bufprintf(struct buf *buf, const char *fmt, ...);

void
bufput(struct buf *buf, const void *data, size_t len);

void
bufputs(struct buf *buf, const char *str);

void
bufputc(struct buf *buf, char c);

void
bufrelease(struct buf *buf);

void
bufreset(struct buf *buf);

void
bufset(struct buf **dest, struct buf *src);

void
bufslurp(struct buf *buf, size_t len);

int
buftoi(struct buf *buf, size_t offset_i, size_t *offset_o);

void
vbufprintf(struct buf *buf, const char *fmt, va_list ap);

extern long buffer_stat_nb;
extern size_t buffer_stat_alloc_bytes;

πŸ¦‹ DESCRIPTION πŸ¦‹

🌈 Variables

Compile time options. Statistics are kept about memory usage. πŸ‘€βœ¨

  • buffer_stat_nb β€” show how many buffers were created. she's counting, and she's keeping receipts 🧾
  • buffer_stat_alloc_bytes β€” show how many bytes were allocated. the receipts, but in bytes πŸ’Ύ

🌸 Types

struct buf

character array buffer. Consists of the following fields:

  • char * data β€” actual character data. the real ones ✨
  • size_t size β€” size of the string. how much is actually in there πŸ’…
  • size_t asize β€” allocated size (0 = volatile buffer). how much room she booked πŸŽ€
  • size_t unit β€” reallocation unit size (0 = read-only buffer). how much she grows by when she needs more πŸ¦‹
  • int ref β€” reference count. how many besties are holding onto her 🫢

🧚 Macros

  • CONST_BUF β€” create a global buffer name from a string literal string. πŸ›οΈ
  • VOLATILE_BUF β€” create a volatile buffer name on the stack from a string strname. 🫧
  • BUFPUTSL β€” optimized bufputs() of a string literal. speed, but make it ✨aesthetic✨

πŸ‘‘ Functions

  • bufcasecmp() β€” compare two buffers ignoring case. not judgmental, just lowercase about it πŸ’…
  • bufcmp() β€” compare two buffers. who's bigger, bestie πŸ“
  • bufcmps() β€” compare a buffer to a string. buffer vs. the literal 😭
  • bufdup() β€” duplicate a buffer src. twin energy, lowkey iconic πŸ‘―
  • bufgrow() β€” increase the allocated size to the given value. glow-up, but measured in bytes πŸ“ˆ
  • bufnew() β€” create a new buffer. brand new baby, periodt ⭐
  • bufnullterm() β€” terminate the string array by NUL (making a C-string). closing the group chat properly πŸ”š
  • bufprintf() β€” print formatted output to a buffer buf. formatted, so she's fancy πŸŽ€
  • bufput() β€” append raw data to a buffer buf. raw, unfiltered, no cap 🌢️
  • bufputs() β€” append a NUL-terminated string str to a buffer buf. the classic move ✨
  • bufputc() β€” append a single char c to a buffer buf. one little letter, main character energy πŸ‘‘
  • bufrelease() β€” decrease the reference count and free the buffer buf if needed. letting her go when nobody's holding on anymore 😭
  • bufreset() β€” free internal data of the buffer buf. internal spring cleaning 🧹
  • bufset() β€” safely assign a buffer to another. handoff, but safe, no drama 🫢
  • bufslurp() β€” remove a given number of bytes from the head of the array. slurp πŸ’€ bye bytes
  • buftoi() β€” convert the numbers at the beginning of the buffer buf into an int. math era πŸ”’
  • vbufprintf() β€” stdarg(3) variant of formatted printing into a buffer buf. the va_list cousin of bufprintf() 🌈

πŸ’… RETURN VALUES πŸ’…

the bufcasecmp(), bufcmp() and bufcmps() functions return an integer less than, equal to, or greater than zero if a is found, respectively, to be less than, to match, or be greater than b. yes, three outcomes, she's flexible πŸ’–

the bufdup() and bufnew() functions return a struct buf * on success; on error they return NULL. 🌧️

the bufgrow() function returns on success 1; on error - 0. that's the whole vibe check βœ…

the bufnullterm(), bufprintf(), bufput(), bufputs(), bufputc(), bufrelease(), bufreset(), bufset(), bufslurp() and vbufprintf() functions do not return a value. they just do the thing and leave πŸ«₯✨

the buftoi() function return the converted value. yes, "return", singular, we don't argue with the original 🫢


πŸ”₯ SEE ALSO πŸ”₯

soldout(3), stdarg(3) β€” go read those too bestie, iykyk πŸ“šπŸ’œ


πŸ“ AUTHORS πŸ“

the soldout library was written by Natasha "Kerensikova" Porte <natacha@instinctive.eu>. πŸ’–

manual page was originally written by Massimo Manghi <mxmanghi@apache.org>, and rewritten to mdoc format by Svyatoslav Mishyn <juef@openmailbox.org>. πŸŽ€


and that's the whole page, bestie πŸ’… this one shipped from Debian on April 13, 2016, and it's SOLDOUT_BUFFER(3) forever and always. slay, stay buffered, drink water πŸ¦‹πŸ’–βœ¨

πŸ“¦ where this page comes from