{"id":20008206,"url":"https://github.com/zigembeddedgroup/foundation-libc","last_synced_at":"2025-05-04T19:34:38.678Z","repository":{"id":215327769,"uuid":"738662694","full_name":"ZigEmbeddedGroup/foundation-libc","owner":"ZigEmbeddedGroup","description":"A libc implementation written in Zig that is designed to be used with freestanding targets.","archived":false,"fork":false,"pushed_at":"2024-06-16T09:40:40.000Z","size":46,"stargazers_count":28,"open_issues_count":0,"forks_count":3,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-06-16T10:52:27.448Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ZigEmbeddedGroup.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-01-03T18:45:29.000Z","updated_at":"2024-06-16T09:40:42.000Z","dependencies_parsed_at":"2024-05-21T23:22:21.430Z","dependency_job_id":null,"html_url":"https://github.com/ZigEmbeddedGroup/foundation-libc","commit_stats":null,"previous_names":["zigembeddedgroup/foundation-libc"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZigEmbeddedGroup%2Ffoundation-libc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZigEmbeddedGroup%2Ffoundation-libc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZigEmbeddedGroup%2Ffoundation-libc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZigEmbeddedGroup%2Ffoundation-libc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ZigEmbeddedGroup","download_url":"https://codeload.github.com/ZigEmbeddedGroup/foundation-libc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224406191,"owners_count":17305725,"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-13T07:08:52.638Z","updated_at":"2025-05-04T19:34:38.663Z","avatar_url":"https://github.com/ZigEmbeddedGroup.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Foundation libc\n\nThis repo has been archived and moved to: https://github.com/ZigEmbeddedGroup/microzig/tree/main/modules/foundation-libc\n\n[![Continuous Integration](https://github.com/ZigEmbeddedGroup/foundation-libc/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/ZigEmbeddedGroup/foundation-libc/actions/workflows/build.yml)\n\n\nA C standard library that only implements a subset of functions that can be safely used without an operating system.\nThis is called a [freestanding environment](https://en.cppreference.com/w/cpp/freestanding).\n\nThis libc is primarily meant to be used with microcontrollers, hobbyist operating systems and so on.\n\n## Support\n\nThe first goal is to reach full C11 *freestanding* support.\n\n- No support for locales\n- No allocator (ship your own!)\n- No support for functions that require an operating system of sorts in the background.\n- No support for `wchar_t` and `wchar.h` as it isn't portable between compilers.\n- Multi-byte character strings are implemented as UTF-8.\n\n## Customization\n\nFoundation libc doesn't really support much customization/configuration except for the hard required options.\n\nThere is [`foundation/libc.h`](include/foundation/libc.h) which documents the behaviour of all required configurations.\n\nRight now, the following configurations exist:\n\n- `foundation_libc_panic_handler`, which allows users to catch detectable undefined behaviour.\n\nYou can also configure the libc by chosing the build mode:\n\n- `Debug`: Implements additional safety checks and adds breakpoints in panics.\n- `ReleaseSafe`: Keeps the safety checks, but removes breakpoints.\n- `ReleaseSmall`: Still keeps a certain amount of safety, but drops long internal strings to reduce code and ram size.\n- `ReleaseFast`: Gotta go fast. Drops all safety and assumes all code behaves well.\n\nThere are also certain \"usage\" configurations that can be chosen to affect behaviour when *using* the headers. Those are implemented as C macros/defines:\n\n- `FOUNDATION_LIBC_ASSERT` is a global macro that defines how `assert()` should behave:\n  - `FOUNDATION_LIBC_ASSERT_DEFAULT=0`: Behaves like a regular assert that can print file name, assertion message and line.\n  - `FOUNDATION_LIBC_ASSERT_NOFILE=1`: Drops the filename from the assertion to reduce code size.\n  - `FOUNDATION_LIBC_ASSERT_NOMSG=2`: Additionally drops the assertion message from the assertion to reduce code size.\n  - `FOUNDATION_LIBC_ASSERT_EXPECTED=3`: Replaces `assert(…)` with a construct that tells the compiler the assertion is always met. Makes code very fast. Assertions aren't checked.\n\n## Development\n\nZig Version: 0.11\n\nRun\n```sh-session\nuser@microzig ~/foundation-libc $ zig build\nuser@microzig ~/foundation-libc $ \n```\n\nto compile the libc and generate a lib file in `zig-out/lib` as well as the headers in `zig-out/include`.\n\n## Contribution\n\nStart by grabbing a header marked with ⏳ or 🛠 and implement the functions from that header. See if others already have a PR open for those functions so you don't do work twice!\n\nLeverage functions from Zig `std` if possible as they are already well tested and should work.\n\nWhich functions belong into which header can be figured out by taking a look at the *C11 Standard Draft* document or the *IBM libc functions* list. [cppreference.com](https://en.cppreference.com/w/c) usually has the better docs though, so best check out both.\n\n### Style Guides\n\n- The header files are ment to be as minimal as possible\n  - Do not use comments documenting the functions, they are well documented everywhere else.\n  - Only insert empty lines between functions if necessarity for clarity\n  - Keep function names sorted alphabetically\n- Try not to use macros at all\n- Use `clang-format` with the provided style file.\n\n\n## Links\n\n- [C11 Standard](https://www.iso.org/standard/57853.html)\n- [C11 Standard Draft](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1548.pdf)\n- [ziglibc](https://github.com/marler8997/ziglibc) \n- [libc-test](https://wiki.musl-libc.org/libc-test.html) by musl\n- [cppreference on freestanding](https://en.cppreference.com/w/cpp/freestanding)\n- [GCC on freestanding](https://gcc.gnu.org/onlinedocs/gcc/Standards.html#C-Language)\n- [IBM libc functions](https://www.ibm.com/docs/en/i/7.5?topic=extensions-standard-c-library-functions-table-by-name) (function to header map)\n- [cppreference](https://en.cppreference.com/w/c)\n- [clang-format style options](https://releases.llvm.org/16.0.0/tools/clang/docs/ClangFormatStyleOptions.html)\n\n## Status\n\n⏳ (not started), 🛠 (work in progress), ⚠️ (partial support), ✅ (full support), ❌ (no support), 🔮 (potential future support), 🔀 (implemented by compiler)\n\n| Header File     | Header Status | Implementation Status | Description                                                                                             |\n| --------------- | ------------- | --------------------- | ------------------------------------------------------------------------------------------------------- |\n| `assert.h`      | ✅             | ✅                     | Conditionally compiled macro that compares its argument to zero                                         |\n| `complex.h`     | ❌             |                       | (since C99) Complex number arithmetic                                                                   |\n| `ctype.h`       | ✅             | ✅                     | Functions to determine the type contained in character data                                             |\n| `errno.h`       | ✅             | ✅                     | Macros reporting error conditions                                                                       |\n| `fenv.h`        | 🔮             |                       | (since C99) Floating-point environment                                                                  |\n| `float.h`       | 🔀             |                       | Limits of floating-point types                                                                          |\n| `inttypes.h`    | ⏳             | ⏳                     | (since C99) Format conversion of integer types                                                          |\n| `iso646.h`      | 🔀             |                       | (since C95) Alternative operator spellings                                                              |\n| `limits.h`      | 🔀             |                       | Ranges of integer types                                                                                 |\n| `locale.h`      | ❌             |                       | Localization utilities                                                                                  |\n| `math.h`        | 🛠             | ⏳                     | Common mathematics functions                                                                            |\n| `setjmp.h`      | 🛠             | ⏳                     | Nonlocal jumps                                                                                          |\n| `signal.h`      | ❌             |                       | Signal handling                                                                                         |\n| `stdalign.h`    | 🔀             |                       | (since C11) alignas and alignof convenience macros                                                      |\n| `stdarg.h`      | 🔀             |                       | Variable arguments                                                                                      |\n| `stdatomic.h`   | 🔮             |                       | (since C11) Atomic operations                                                                           |\n| `stdbit.h`      | 🔮             |                       | (since C23) Macros to work with the byte and bit representations of types                               |\n| `stdbool.h`     | 🔀             |                       | (since C99) Macros for boolean type                                                                     |\n| `stdckdint.h`   | 🔮             |                       | (since C23) macros for performing checked integer arithmetic                                            |\n| `stddef.h`      | 🔀             |                       | Common macro definitions                                                                                |\n| `stdint.h`      | 🔀             |                       | (since C99) Fixed-width integer types                                                                   |\n| `stdio.h`       | ❌             |                       | Input/output                                                                                            |\n| `stdlib.h`      | 🛠             | 🛠                     | General utilities: memory management, program utilities, string conversions, random numbers, algorithms |\n| `stdnoreturn.h` | 🔀             |                       | (since C11) noreturn convenience macro                                                                  |\n| `string.h`      | ✅             | 🛠                     | String handling                                                                                         |\n| `tgmath.h`      | ⏳             | ⏳                     | (since C99) Type-generic math (macros wrapping math.h and complex.h)                                    |\n| `threads.h`     | ❌             |                       | (since C11) Thread library                                                                              |\n| `time.h`        | ❌             |                       | Time/date utilities                                                                                     |\n| `uchar.h`       | 🛠             | ⏳                     | (since C11) UTF-16 and UTF-32 character utilities                                                       |\n| `wchar.h`       | ❌             |                       | (since C95) Extended multibyte and wide character utilities                                             |\n| `wctype.h`      | ❌             |                       | (since C95) Functions to determine the type contained in wide character data                            |\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzigembeddedgroup%2Ffoundation-libc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzigembeddedgroup%2Ffoundation-libc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzigembeddedgroup%2Ffoundation-libc/lists"}