Skip to content
rootmosPublic

About

Opinionated public domain C snippets

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

148 Commits

Folders and files

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 with the fail and logging modules:

./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!

Deployment

In your project's Makefile:

LIBR = fail logging
r.h:
	wget -O- https://raw.githubusercontent.com/rootmos/libr/refs/heads/master/bundle | python - --clone --output=$@ $(LIBR)

Modules

About

Opinionated public domain C snippets

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages