{"id":21866867,"url":"https://github.com/rootmos/libr","last_synced_at":"2025-03-21T21:24:54.756Z","repository":{"id":82433876,"uuid":"176459577","full_name":"rootmos/libr","owner":"rootmos","description":"Opinionated public domain C snippets","archived":false,"fork":false,"pushed_at":"2024-11-02T12:41:13.000Z","size":249,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-26T16:12:52.248Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rootmos.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-19T08:14:13.000Z","updated_at":"2024-11-02T12:41:17.000Z","dependencies_parsed_at":"2023-11-07T00:34:37.856Z","dependency_job_id":"3bdf05f6-7874-4ddb-936c-bdfe609fb96e","html_url":"https://github.com/rootmos/libr","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rootmos%2Flibr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rootmos%2Flibr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rootmos%2Flibr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rootmos%2Flibr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rootmos","download_url":"https://codeload.github.com/rootmos/libr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244870828,"owners_count":20523937,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-28T05:07:46.675Z","updated_at":"2025-03-21T21:24:54.736Z","avatar_url":"https://github.com/rootmos.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# libr\n[![Build and test](https://github.com/rootmos/libr/actions/workflows/test.yaml/badge.svg)](https://github.com/rootmos/libr/actions/workflows/test.yaml)\n\nOpinionated public domain C snippets and helpers,\nbundled as a [single-file library](https://github.com/nothings/stb).\n\n## Usage\nSelect a few modules: from the list below or run `bundle -l` to list the\navailable modules.\nFor instance: `fail` and `logging`:\n```shell\n~/git/libr/bundle --output=r.h fail logging\n```\nThen `hello.c` can check for errors and do logging:\n```c\n#define LIBR_IMPLEMENTATION\n#include \"r.h\"\n\nint main(int argc, char* argv[])\n{\n    if(argc != 2) {\n        failwith(\"incorrect number of arguments: %d != 2\", argc);\n    }\n\n    info(\"hello %s world!\", argv[1]);\n\n    int r = close(0);\n    CHECK(r, \"close(%d)\", 0);\n\n    void* buf = malloc(4096); CHECK_MALLOC(buf);\n\n    return 0;\n}\n```\nwhich when built and run:\n```shell\ngcc -DLOG_LEVEL=LOG_INFO -o hello hello.c\n./hello libr\n```\nsays hello:\n```\n20230906T105013Z:1530871:main:hello.c:10 hello libr world!\n```\n\n## Modules\n- **base32**: implementation of the RFC4648 Base32 encoding\u003cbr\u003e [.h](modules/base32.h) [.c](modules/base32.c) [.test.c](modules/base32.test.c) [reference](https://datatracker.ietf.org/doc/html/rfc4648)\n- **char**: helpers to interpret ASCII characters\u003cbr\u003e [.h](modules/char.h)\n- **crc**: implementation of CRC16-ccitt\u003cbr\u003e [.h](modules/crc.h) [.c](modules/crc.c) [.test.c](modules/crc.test.c) [wiki](https://en.wikipedia.org/wiki/Computation_of_cyclic_redundancy_checks)\n- **devnull**: /dev/null as a filedescriptor\u003cbr\u003e [.h](modules/devnull.h) [.c](modules/devnull.c) [man](https://man.archlinux.org/man/zero.4.en)\n- **env**: getenv wrappers\u003cbr\u003e [.h](modules/env.h) [.c](modules/env.c) [man](https://man.archlinux.org/man/getenv.3.en)\n- **fail**: abort-based error handling\u003cbr\u003e [.h](modules/fail.h) [.c](modules/fail.c) [man](https://man.archlinux.org/man/abort.3.en)\n- **file**: read file line-by-line or as a whole\u003cbr\u003e [.h](modules/file.h) [.c](modules/file.c)\n- **hex**: hexadecimal binary encoding\u003cbr\u003e [.h](modules/hex.h) [.c](modules/hex.c) [.test.c](modules/hex.test.c)\n- **hexdump**: hexdump troubleshooting utility\u003cbr\u003e [.h](modules/hexdump.h) [.c](modules/hexdump.c)\n- **landlock**: Linux landlock syscall wrappers and helpers\u003cbr\u003e [.h](modules/landlock.h) [.c](modules/landlock.c) [reference](https://www.kernel.org/doc/html/latest/userspace-api/landlock.html) [man](https://man.archlinux.org/man/landlock.7.en)\n- **logging**: compiletime eliminated printf-style logging\u003cbr\u003e [.h](modules/logging.h) [.c](modules/logging.c)\n- **lua**: Lua error checking and stack helpers\u003cbr\u003e [.h](modules/lua.h) [.c](modules/lua.c) [reference](https://www.lua.org/manual/5.4/manual.html#4.4)\n- **mark**: realtime frequency calculation\u003cbr\u003e [.h](modules/mark.h) [.c](modules/mark.c)\n- **no_new_privs**: prctl(PR_SET_NO_NEW_PRIVS) helper\u003cbr\u003e [.h](modules/no_new_privs.h) [.c](modules/no_new_privs.c) [reference](https://www.kernel.org/doc/html/latest/userspace-api/no_new_privs.html) [man](https://man.archlinux.org/man/prctl.2.en#PR_SET_NO_NEW_PRIVS)\n- **nonblock**: helper to set/unset O_NONBLOCK flag\u003cbr\u003e [.h](modules/nonblock.h) [.c](modules/nonblock.c) [man](https://man.archlinux.org/man/fcntl.2.en#F_SETFL)\n- **now**: current time in ISO8601 format\u003cbr\u003e [.h](modules/now.h) [.c](modules/now.c) [wiki](https://en.wikipedia.org/wiki/ISO_8601)\n- **path**: path mangling\u003cbr\u003e [.h](modules/path.h) [.c](modules/path.c) [.test.c](modules/path.test.c)\n- **rlimit**: apply strict rlimits\u003cbr\u003e [.h](modules/rlimit.h) [.c](modules/rlimit.c) [man](https://man.archlinux.org/man/setrlimit.2.en)\n- **seccomp**: seccomp syscall wrapper\u003cbr\u003e [.h](modules/seccomp.h) [.c](modules/seccomp.c) [reference](https://www.kernel.org/doc/html/latest/userspace-api/seccomp_filter.html) [man](https://man.archlinux.org/man/seccomp.2.en)\n- **sha1**: SHA-1 implementation\u003cbr\u003e [.h](modules/sha1.h) [.c](modules/sha1.c) [.test.c](modules/sha1.test.c) [wiki](https://en.wikipedia.org/wiki/Secure_Hash_Algorithms) [reference](https://www.rfc-editor.org/rfc/rfc3174)\n- **sha2**: SHA-2 implementation\u003cbr\u003e [.h](modules/sha2.h) [.c](modules/sha2.c) [.test.c](modules/sha2.test.c) [wiki](https://en.wikipedia.org/wiki/Secure_Hash_Algorithms) [reference](https://www.rfc-editor.org/rfc/rfc6234)\n- **stopwatch**: pausable realtime frequency calculation\u003cbr\u003e [.h](modules/stopwatch.h) [.c](modules/stopwatch.c)\n- **str**: string helpers\u003cbr\u003e [.h](modules/str.h) [.c](modules/str.c) [.test.c](modules/str.test.c)\n- **test**: test utilities\u003cbr\u003e [.h](modules/test.h) [.c](modules/test.c)\n- **util**: LENGTH, LIT, MAX, MIN macros\u003cbr\u003e [.h](modules/util.h)\n- **uv**: uv error-checking\u003cbr\u003e [.h](modules/uv.h) [reference](http://docs.libuv.org/en/v1.x/errors.html#c.uv_err_name)\n- **xdg**: XDG base directories\u003cbr\u003e [.h](modules/xdg.h) [.c](modules/xdg.c) [reference](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html)\n- **xorshift**: implementation of xorshift64 and xorshift128+\u003cbr\u003e [.h](modules/xorshift.h) [.c](modules/xorshift.c) [.test.c](modules/xorshift.test.c) [wiki](https://en.wikipedia.org/wiki/Xorshift)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frootmos%2Flibr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frootmos%2Flibr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frootmos%2Flibr/lists"}