stringlist(3bsd)

πŸ“¦
version 0.12.2 Β· 2 versions
  • 0.12.2 Β· alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, debian bookworm, debian trixie, epel 10, epel 9, fedora 43, fedora 44, nixos 26.05, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 0.11.5 Β· ubuntu jammy
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, debian bookworm, debian trixie, epel 10, epel 9, fedora 43, fedora 44, nixos 26.05, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– stringlist(3bsd) β€” LOCAL πŸ’–

okay bestie, welcome to stringlist(3bsd) from the <rainbow>LOCAL</rainbow> manual, section 3bsd β€” yes it's giving very "I read man pages for fun" but honestly? same. πŸŽ€


✨ NAME ✨

stringlist, sl_init, sl_add, sl_free, sl_find, sl_delete β€” the stringlist manipulation functions, aka the little squad that handles your lists of strings for you. πŸ‘‘


πŸ“š LIBRARY πŸ“š

Utility functions from BSD systems β€” that's libbsd, link it with -lbsd. 🫢


🌸 SYNOPSIS 🌸

#include <stringlist.h>

(psst β€” go check libbsd(7) for how the include actually works, no cap. πŸ‘€)

StringList *
sl_init(void);

int
sl_add(StringList *sl, char *item);

void
sl_free(StringList *sl, int freeall);

char *
sl_find(StringList *sl, const char *item);

int
sl_delete(StringList *sl, const char *item, int freeit);

πŸ¦‹ DESCRIPTION πŸ¦‹

So the stringlist functions do exactly what it says on the tin: they manipulate stringlists, which are literally lists of strings that extend automatically if necessary. it's giving self-care, honestly. she grows when she needs to. πŸ’…

The StringList structure has this exact definition:

typedef struct _stringlist {
        char    **sl_str;
        size_t    sl_max;
        size_t    sl_cur;
} StringList;

where:

  • sl_str β€” is a pointer to the base of the array containing the list. (the home base, the main character. 🏠)
  • sl_max β€” is the size of sl_str. (how much room she's got. πŸ“)
  • sl_cur β€” is the offset in sl_str of the current element. (where we're at rn. πŸ“)

The following stringlist manipulation functions are available:

  • sl_init() β€” Create a stringlist. Returns a pointer to a StringList, or NULL in case of failure. ✨ (manifesting a non-NULL return for you bestie, but be ready for that NULL fr fr.)
  • sl_free() β€” Releases memory occupied by sl and the sl->sl_str array. If freeall is non-zero, then each of the items within sl->sl_str is released as well. 🧹 (that second part is the deep clean β€” only if freeall is non-zero, don't come for me.)
  • sl_add() β€” Add item to sl->sl_str at sl->sl_cur, extending the size of sl->sl_str. Returns zero upon success, -1 upon failure. πŸ’–
  • sl_find() β€” Find item in sl, returning NULL if it's not found. πŸ” (ghosted, but politely.)
  • sl_delete() β€” Remove item from the list. If freeit is non-zero, the string is freed. Returns 0 if the name is found and -1 if the name is not found. πŸ’€βž‘οΈπŸ•ŠοΈ

πŸ‘€ SEE ALSO πŸ‘€

free(3), malloc(3) β€” go read those too, they're the OGs. 🌈


πŸ“œ HISTORY πŸ“œ

The stringlist functions appeared in FreeBSD 2.2.6 and NetBSD 1.3. vintage but still slaying. πŸ‘‘


cute little sign-off: this page came from Debian and it's dated May 6, 2010 β€” yeah she's a Taurus-era icon and we love her for it. πŸŽ€πŸ¦‹βœ¨ bye bestie, go sl_free your leaks πŸ’œ

πŸ“¦ where this page comes from