STRBUF(3)
β¨ STRBUF(3) β¨
okay bestie, sit DOWN because we're about to talk about the Unidata string-buffer β it's from the UNIDATA LIBRARY FUNCTIONS section of the manual, and honestly? it's giving "strings but with zero size anxiety". π
π NAME π
strbuf, sbnew, sbcpy, sbncpy, sbcat, sbncat, sbstr, sblen, sbmax, sbgrow, sbfree β the whole Unidata string-buffer friend group. π«Ά
πΈ SYNOPSIS πΈ
#include "udposix.h"
#include <stddef.h> /* for "size_t" */
#include "strbuf.h"
Strbuf *sbnew(size_t max)
Strbuf *sbensure(Strbuf *sb, size_t max)
Strbuf *sbcpy(Strbuf *sb, const char *string)
Strbuf *sbncpy(Strbuf *sb, const char *string, size_t len)
Strbuf *sbcat(Strbuf *sb, const char *string)
Strbuf *sbncat(Strbuf *sb, const char *string, size_t len)
char *sbstr(const Strbuf *sb)
size_t sblen(const Strbuf *sb)
size_t sbmax(const Strbuf *sb)
Strbuf *sbgrow(Strbuf *sb)
Strbuf *sbfree(Strbuf *sb)
π DESCRIPTION π
These routines define the Unidata string-buffer abstraction. What does that even mean? It means you get to operate on strings without ever worrying about size β like, arbitrary concatenation, no mental math, no panic, no nothing. iconic behavior fr fr. π
π¦ the functions, one by one π¦
sbnew()β creates a brand-new instance of a string buffer.maxis the initial maximum size of the string buffer, aka the number of characters the buffer may hold, excluding the terminating\0character. and yes, the buffer will grow beyond this size if it has to, but bestie, it's literally in your own interest to setmaxto something appropriate (like, enough to hold 90% of its potential population). This function returns the new string-buffer, orNULLif an error occurs. πsbensure()β ensures that the string buffer will be able to contain a string havingmaxcharacters (again, excluding the terminating\0). This function returns the new string-buffer, orNULLif an error occurs.sbcpy()β sets the string-buffer tostring, which must be 0-terminated. If successful, this function returns the original string-buffer. If an error occurs, this function returnsNULLand the string-buffer is unchanged (no half-done mess, we respect boundaries here β¨).sbncpy()β sets the string-buffer tostring.lenis the number of characters instringto use and should exclude any terminating\0character. If successful, this function returns the original string-buffer. If an error occurs, this function returnsNULLand the string-buffer is unchanged.sbcat()β appendsstring, which must be 0-terminated, to the contents of the string-buffer. If the string-buffer has not been set via an earlier call tosbcpy()orsbncpy(), then the result is the same assbcpy(sb, string). If successful, this function returns the original string-buffer. If an error occurs, this function returnsNULLand the string-buffer is unchanged.sbncat()β appendsstringto the contents of the string-buffer.lenis the number of characters to append and should exclude any terminating\0character. If the string-buffer has not been set via an earlier call tosbcpy()orsbncpy(), then the result is the same assbcpy(sb, string). If successful, this function returns the original string-buffer. If an error occurs, this function returnsNULLand the string-buffer is unchanged.sbstr()β returns a pointer to the\0-terminated string in the string-buffer. If the string buffer has not been set, then the pointed-to string is empty β NB: the pointer is notNULL, okay, don't come for me. The returned string pointer may be used like any other string pointer, provided the user has ensured the size of the string-buffer via a call tosbensure(), if appropriate. For example:
(void) sbensure(sb, strlen(string));
(void) strcpy(sbstr(sb), string);
When string buffers are used this way, the calling application is responsible for ensuring proper \0-termination. that's on you, bestie. π«΅
sblen()β returns the number of characters in the string-buffer, excluding the terminating\0character. If the string-buffer has not been set, then the returned length is zero.sbmax()β returns the maximum number of characters that the string-buffer can currently hold, excluding the terminating\0character.sbgrow()β increases the size of the string buffer. this is useful when there's no a priori knowledge of how large the string buffer should be. go forth and grow, queen. πsbfree()β releases the resources used by the string-buffer back to the operating-system and should be called when the string-buffer is no longer needed. It always returns(Strbuf*)NULL. always. no cap.
π§ This package uses the UDPOSIX programming environment and the udalloc(3) memory allocation package. iykyk.
π MAINTAINER π
Steve Emmerson <steve@unidata.ucar.edu>. π«‘
π SEE ALSO π
udalloc(3)udposix(3)
and that's the whole page, babe. π printed 126-10-12, source revision $Date: 2000/08/07 23:15:04 $ β yeah she's an elder but she still ate, and she's still STRBUF(3) in the Unidata library. periodt. π
β¨
π¦ where this page comes from
- debian bookworm: libxgks-dev 2.6.1+dfsg.2-12
- debian trixie: libxgks-dev 2.6.1+dfsg.2-17
- ubuntu jammy: libxgks-dev 2.6.1+dfsg.2-12
- ubuntu noble: libxgks-dev 2.6.1+dfsg.2-15
- ubuntu questing: libxgks-dev 2.6.1+dfsg.2-19ubuntu1
- ubuntu resolute: libxgks-dev 2.6.1+dfsg.2-19ubuntu2
- ubuntu stonking: libxgks-dev 2.6.1+dfsg.2-19ubuntu2
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms