Skip to content

rootmos/libr

Repository files navigation

libr

Build and test

Opinionated public domain C snippets and helpers, bundled as a single-file library.

Usage

Select a few modules: from the list below or run bundle -l to list the available modules. For instance: fail and logging:

~/git/libr/bundle --output=r.h fail logging

Then hello.c can check for errors and do logging:

#define LIBR_IMPLEMENTATION
#include "r.h"

int main(int argc, char* argv[])
{
    if(argc != 2) {
        failwith("incorrect number of arguments: %d != 2", argc);
    }

    info("hello %s world!", argv[1]);

    int r = close(0);
    CHECK(r, "close(%d)", 0);

    void* buf = malloc(4096); CHECK_MALLOC(buf);

    return 0;
}

which when built and run:

gcc -DLOG_LEVEL=LOG_INFO -o hello hello.c
./hello libr

says hello:

20230906T105013Z:1530871:main:hello.c:10 hello libr world!

Modules

About

Opinionated public domain C snippets

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published