
Register Exit Handlers with atexit and on_exit
atexit registers cleanup functions that run in reverse order when a program ends normally. on_exit also passes the status. Neither runs after _exit or abort.
Tag
6 posts

atexit registers cleanup functions that run in reverse order when a program ends normally. on_exit also passes the status. Neither runs after _exit or abort.

Use getopt_long in C to accept --name and --name=value options, fill in the option table, handle flags and abbreviations, and keep short options working.

Decide who frees every heap block in C by naming owners and borrowers, marking transfers in function contracts, and following a few conventions that stop leaks.

strerror_r has two incompatible signatures in glibc. Learn which one you get, how to write code that works with both, and how strerror_l avoids the problem.

Bundle a Linux program with its libraries in one folder that runs from any path, using an $ORIGIN runpath, ldd to collect dependencies and a launcher check.

Learn malloc, calloc, realloc and free from scratch, the bugs they cause, who owns each pointer, and what glibc does underneath, with tested patterns.