ECALLOC(3)

✨ ECALLOC(3) ✨

okay bestie, we're in section 3 of the manual (library functions, the fun one πŸ’…) and today's main character is a whole little squad of wrapper functions: ecalloc, emalloc, eread, erealloc, esetenv, estrdup, and ewrite. they live in the roken library and they are, collectively, the exit-on-failure wrapper functions. yes that's the whole vibe: do the thing, and if the thing fails, we are LEAVING. πŸšͺπŸ’¨


πŸ“š LIBRARY

the roken library β€” that's libroken, link it with -lroken πŸŽ€


πŸ¦‹ SYNOPSIS

#include <roken.h>

void *
ecalloc(size_t number, size_t size);

void *
emalloc(size_t sz);

ssize_t
eread(int fd, void *buf, size_t nbytes);

void *
erealloc(void *ptr, size_t sz);

void
esetenv(const char *var, const char *val, int rewrite);

char *
estrdup(const char *str);

ssize_t
ewrite(int fd, const void *buf, size_t nbytes);

πŸ’– DESCRIPTION

okay so here's the tea β˜• β€” these functions do exactly the same thing as their non-e siblings. same energy, same args, same job. the difference? if there's an error, they print a message with errx(3) and then they exit. like, no recovery, no second chances, no "let me handle this gracefully". it's giving we die like legends 😭

and for eread and ewrite, bestie, that goes for partial data too β€” not just full-on errors. partial read? partial write? still an exit. the function said "all or nothing" and it MEANT it. πŸ‘‘

so when is this actually useful? when your application doesn't need a more advanced failure mode. you know the type β€” the program where if the malloc fails, everything is over anyway, so why write 40 lines of error handling. lowkey iconic honestly. 🫢


πŸ‘€ SEE ALSO


and that's the whole page, bestie!! this one comes to you from HEIMDAL, dated August 14, 2003 β€” a certified classic, still slaying πŸ’…βœ¨ bye love u, go read your error messages πŸŽ€

πŸ“¦ where this page comes from