{"id":22925343,"url":"https://github.com/ringtailsoftware/zeptolibc","last_synced_at":"2025-08-14T12:33:50.677Z","repository":{"id":266664564,"uuid":"898979733","full_name":"ringtailsoftware/zeptolibc","owner":"ringtailsoftware","description":"Some basic libc functions for working with C code in Zig","archived":false,"fork":false,"pushed_at":"2024-12-08T16:41:17.000Z","size":52,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-14T09:01:44.352Z","etag":null,"topics":["libc","zig","zig-package"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ringtailsoftware.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-12-05T11:55:40.000Z","updated_at":"2024-12-13T03:04:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"f98b35e6-d628-4f56-9a40-cd7247f5369a","html_url":"https://github.com/ringtailsoftware/zeptolibc","commit_stats":null,"previous_names":["ringtailsoftware/zeptolibc"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ringtailsoftware%2Fzeptolibc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ringtailsoftware%2Fzeptolibc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ringtailsoftware%2Fzeptolibc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ringtailsoftware%2Fzeptolibc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ringtailsoftware","download_url":"https://codeload.github.com/ringtailsoftware/zeptolibc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229827776,"owners_count":18130394,"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":["libc","zig","zig-package"],"created_at":"2024-12-14T09:00:37.813Z","updated_at":"2024-12-15T14:11:40.710Z","avatar_url":"https://github.com/ringtailsoftware.png","language":"Zig","funding_links":[],"categories":["Systems Programming"],"sub_categories":["Embedded Development"],"readme":"# ZeptoLibC\n\nA few of the most essential libc functions needed when working with C code in Zig.\n\nMuch of the code is taken from [ziglibc](https://github.com/marler8997/ziglibc).\n\nZeptoLibC provides, among others:\n\n - `malloc()`, `calloc()`, `realloc()`, `free()`\n - `printf()`, `fprintf()`, `snprintf()`\n - `strncmp()`, `strchr()`, `strncpy()`\n - `abs()`, `fabs()`, `sin()`, `cos()`, `sqrt()`, `pow()`, `floor()`, `ceil()`\n - `memset()`, `memmove()`\n\nZeptoLibC is not intended to implement the full C library and does the bare minimum to support I/O operations (just `printf()`). The aim is to allow simple porting of existing C code to freestanding/baremetal environments such as WASM and embedded systems.\n\nAll ZeptoLibC functions start with the prefix `zepto_`, eg. `zepto_malloc()` so as to not clash with any existing C functions. The file `zeptolibc.h` provides `#define`s for mapping `malloc()` -\u003e `zepto_malloc()`.\n\n# How to use\n\nFor a complete example, see https://github.com/ringtailsoftware/zeptolibc-example\n\nFirst we add the library as a dependency in our `build.zig.zon` file.\n\n`zig fetch --save git+https://github.com/ringtailsoftware/zeptolibc.git`\n\nAnd we add it to `build.zig` file.\n```zig\nconst zeptolibc_dep = b.dependency(\"zeptolibc\", .{\n    .target = target,\n    .optimize = optimize,\n});\n\nexe.root_module.addImport(\"zeptolibc\", zeptolibc_dep.module(\"zeptolibc\"));\nexe.addIncludePath(zeptolibc_dep.path(\"src/\"));\n```\n\n# Usage:\n\nAdd `#include \"zeptolibc.h\"` to your C code.\n\n```c\n    #include \"zeptolibc.h\"\n\n    void my_greeting(void) {\n        printf(\"Hello world\\n\");\n    }\n```\n\nSetup ZeptoLibC from Zig and call the C code.\n\n`zeptolibc.init()` may be passed `null` for both write function and allocator. A `null` allocator will cause `malloc()` to always return `NULL`. A `null` write function will silently drop written data.\n\n```zig\n    const std = @import(\"std\");\n    const zeptolibc = @import(\"zeptolibc\");\n\n    const c = @cImport({\n        @cInclude(\"greeting.c\");\n    });\n\n    fn writeFn(data:[]const u8) void {\n        _ = std.io.getStdOut().writer().write(data) catch 0;\n    }\n\n    pub fn main() !void {\n        var gpa = std.heap.GeneralPurposeAllocator(.{}){};\n        const allocator = gpa.allocator();\n\n        // init zepto with a memory allocator and a write function (used for stdout and stderr)\n        zeptolibc.init(allocator, writeFn);\n\n        c.my_greeting();\n    }\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fringtailsoftware%2Fzeptolibc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fringtailsoftware%2Fzeptolibc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fringtailsoftware%2Fzeptolibc/lists"}