qlibs(stralloc)

πŸ“¦ version 31, in alpine 3.24

πŸ’– stralloc β€” dynamically allocated strings πŸ’–

okay so this is the qlibs(stralloc) page, bestie β€” manual name folded in right at the top, exactly as requested. It's giving dynamic strings, memory-powered growth, and absolutely no length drama beyond what memory allows. ✨


✨ NAME ✨

stralloc β€” dynamically allocated strings

πŸ¦‹ SYNTAX πŸ¦‹

the exact lineup, no edits, no vibes-based changes:

#include "stralloc.h"

int stralloc_ready(&sa,len);
int stralloc_readyplus(&sa,len);

int stralloc_copy(&sa,&sa2);
int stralloc_copys(&sa,buf);
int stralloc_copyb(&sa,buf,len);

int stralloc_cat(&sa,&sa2);
int stralloc_cats(&sa,buf);
int stralloc_catb(&sa,buf,len);

int stralloc_append(&sa,buf);
int stralloc_0(&sa);

int stralloc_free(&sa);

int stralloc_starts(&sa,buf);

void stralloc_free(&sa);

stralloc sa = {0};
stralloc sa2 = {0};
unsigned int len;
char *buf;
yep, stralloc_free shows up twice in that block β€” once as int and once as void β€” and both stay exactly as printed. periodt. πŸ’…

🌸 DESCRIPTION 🌸

A stralloc variable holds a string in dynamically allocated space. String length is limited only by memory. String contents are unrestricted.

The stralloc structure has three components:

  • sa.s is a pointer to the string, or 0 if it is not allocated.
  • sa.len is the number of bytes in the string, if it is allocated.
  • sa.a is the number of bytes allocated for the string, if it is allocated.

A stralloc variable should be initialized to {0}, meaning unallocated. iconic empty-start behavior, honestly. 🫢

  • stralloc_ready(&sa,len); β€” makes sure sa has enough space allocated for len characters. It allocates extra space if necessary.
  • stralloc_readyplus(&sa,len); β€” makes sure sa has enough space allocated for len characters more than its current length. If sa is unallocated, stralloc_readyplus is the same as stralloc_ready.
  • stralloc_copy(&sa,&sa2); β€” copies sa2 to sa, allocating space if necessary. Here sa2 is an allocated stralloc variable.
  • stralloc_copys(&sa,buf); β€” copies a 0-terminated string, buf, to sa, without the 0.
  • stralloc_copyb(&sa,buf,len); β€” copies len characters from buf to sa.
  • stralloc_cat(&sa,&sa2); β€” appends sa2 to sa, allocating space if necessary. If sa is unallocated, stralloc_cat is the same as stralloc_copy.
  • stralloc_cats(&sa,buf); β€” analogous to stralloc_copys.
  • stralloc_catb(&sa,buf,len); β€” analogous to stralloc_copyb.
  • stralloc_append(&sa,buf); β€” adds a single character, *buf, to sa, allocating space if necessary.
  • stralloc_0(&sa); β€” adds a single 0 character to sa.
  • stralloc_starts(&sa,buf); β€” returns 1 if the 0-terminated string buf, without the 0, is a prefix of sa.
  • stralloc_free(&sa); β€” deallocates sa and resets len and a. (and yes, the syntax block keeps both the int and void declarations, bestie πŸ’…)

πŸ’€ ERROR HANDLING πŸ’€

If a stralloc routine runs out of memory, it leaves sa alone and returns 0, setting errno appropriately. On success it returns 1; this guarantees that sa is allocated. success = 1 = allocated sa, no cap. 🫢

🌈 SEE ALSO 🌈


later bestie 🫢 β€” source/version: qlibs(stralloc), page 3, and no date is printed on this footer, so that's the whole tea. πŸ’…βœ¨

πŸ“¦ where this page comes from