qlibs(stralloc)
π 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_freeshows up twice in that block β once asintand once asvoidβ 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.sis a pointer to the string, or0if it is not allocated.sa.lenis the number of bytes in the string, if it is allocated.sa.ais 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 suresahas enough space allocated forlencharacters. It allocates extra space if necessary.stralloc_readyplus(&sa,len);β makes suresahas enough space allocated forlencharacters more than its current length. Ifsais unallocated,stralloc_readyplusis the same asstralloc_ready.stralloc_copy(&sa,&sa2);β copiessa2tosa, allocating space if necessary. Heresa2is an allocatedstrallocvariable.stralloc_copys(&sa,buf);β copies a 0-terminated string,buf, tosa, without the 0.stralloc_copyb(&sa,buf,len);β copieslencharacters frombuftosa.stralloc_cat(&sa,&sa2);β appendssa2tosa, allocating space if necessary. Ifsais unallocated,stralloc_catis the same asstralloc_copy.stralloc_cats(&sa,buf);β analogous tostralloc_copys.stralloc_catb(&sa,buf,len);β analogous tostralloc_copyb.stralloc_append(&sa,buf);β adds a single character,*buf, tosa, allocating space if necessary.stralloc_0(&sa);β adds a single0character tosa.stralloc_starts(&sa,buf);β returns1if the 0-terminated stringbuf, without the 0, is a prefix ofsa.stralloc_free(&sa);β deallocatessaand resetslenanda. (and yes, the syntax block keeps both theintandvoiddeclarations, 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
- alpine 3.24: fehqlibs-doc 31-r0 Β· Public-Domain
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms