{"id":30810330,"url":"https://github.com/nickscha/sb","last_synced_at":"2025-09-06T05:05:42.568Z","repository":{"id":313337455,"uuid":"1047823521","full_name":"nickscha/sb","owner":"nickscha","description":"C89, single header, nostdlib string builder","archived":false,"fork":false,"pushed_at":"2025-09-05T10:40:27.000Z","size":51,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-05T12:31:23.737Z","etag":null,"topics":["c89","nostdlib","single-header","string","string-library"],"latest_commit_sha":null,"homepage":"","language":"C","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/nickscha.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-08-31T10:12:12.000Z","updated_at":"2025-09-05T10:40:31.000Z","dependencies_parsed_at":"2025-09-05T12:31:27.599Z","dependency_job_id":"c2e09c92-46e7-45a1-abca-2a228a432ac5","html_url":"https://github.com/nickscha/sb","commit_stats":null,"previous_names":["nickscha/sb"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/nickscha/sb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nickscha%2Fsb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nickscha%2Fsb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nickscha%2Fsb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nickscha%2Fsb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nickscha","download_url":"https://codeload.github.com/nickscha/sb/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nickscha%2Fsb/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273858876,"owners_count":25180772,"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","status":"online","status_checked_at":"2025-09-06T02:00:13.247Z","response_time":2576,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["c89","nostdlib","single-header","string","string-library"],"created_at":"2025-09-06T05:05:41.106Z","updated_at":"2025-09-06T05:05:42.544Z","avatar_url":"https://github.com/nickscha.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sb\nA C89 standard compliant, single header, nostdlib (no C Standard Library) String Builder (SB).\n\nFor more information please look at the \"sb.h\" file or take a look at the \"examples\" or \"tests\" folder.\n\n\u003e [!WARNING]\n\u003e THIS PROJECT IS A WORK IN PROGRESS! ANYTHING CAN CHANGE AT ANY MOMENT WITHOUT ANY NOTICE! USE THIS PROJECT AT YOUR OWN RISK!\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/nickscha/sb/releases\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/v/release/nickscha/sb?style=flat-square\u0026color=blue\" alt=\"Latest Release\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/nickscha/sb/releases\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/downloads/nickscha/sb/total?style=flat-square\u0026color=brightgreen\" alt=\"Downloads\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://opensource.org/licenses/MIT\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square\" alt=\"License\"\u003e\n  \u003c/a\u003e\n  \u003cimg src=\"https://img.shields.io/badge/Standard-C89-orange?style=flat-square\" alt=\"C Standard\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/nolib-nostdlib-lightgrey?style=flat-square\" alt=\"nostdlib\"\u003e\n\u003c/p\u003e\n\n## **Features**\n- **C89 compliant** — portable and legacy-friendly  \n- **Single-header API** — just include `sb.h`  \n- **nostdlib** — no dependency on the C Standard Library  \n- **Minimal binary size** — optimized for small executables  \n- **Cross-platform** — Works on all Platforms\n- **Strict compilation** — built with aggressive warnings \u0026 safety checks (detect buffer overflow via `sb.ovr`)  \n\n## Quick Start\n\nDownload or clone sb.h and include it in your project.\n\n```C\n#include \"sb.h\" /* String Builder */\n\nint main(void) {\n\n    /* Initialize the string builder */\n    char buf[256];\n    sb sb;\n    sb_init(\u0026sb, buf, sizeof(buf));\n\n    /* Examples for formatting numbers */\n    sb_append_cstr(\u0026sb, \"  none: '\");\n    sb_append_long(\u0026sb, 123, 8, SB_PAD_NONE);\n    sb_append_cstr(\u0026sb, \"'\\n\");\n\n    sb_append_cstr(\u0026sb, \"  left: '\");\n    sb_append_long(\u0026sb, 123, 8, SB_PAD_RIGHT);\n    sb_append_cstr(\u0026sb, \"'\\n\");\n\n    sb_append_cstr(\u0026sb, \" right: '\");\n    sb_append_long(\u0026sb, 123, 8, SB_PAD_LEFT);\n    sb_append_cstr(\u0026sb, \"'\\n\");\n\n    sb_append_cstr(\u0026sb, \"double: '\");\n    sb_append_double(\u0026sb, -3.14159, 9, 4, SB_PAD_LEFT);\n    sb_append_cstr(\u0026sb, \"'\\n\");\n\n    sb_append_cstr(\u0026sb, \" float: '\");\n    sb_append_float(\u0026sb, 0.1234f, 9, 4, SB_PAD_LEFT);\n    sb_append_cstr(\u0026sb, \"'\\n\");\n\n    /* Add terminator to string builder */\n    sb_term(\u0026sb);\n\n    /* Afterwards you can print the \"sb.buf\" or \"buf\" directly */\n\n    return 0;\n}\n```\n\nOutput will be:\n\n```txt\n  none: '123'\n  left: '123     '\n right: '     123'\ndouble: '  -3.1416'\n float: '   0.1234'\n```\n\n## Function Reference\n\n| Function                       | Signature                                                                           | Description                                                                       | Return                       |\n| ------------------------------ | ----------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- | ---------------------------- |\n| Initialize SB                  | `void sb_init(sb *sb, char *buffer, int capacity)`                                  | Initialize string builder with a buffer.                                          | –                            |\n| Terminate SB                   | `void sb_term(sb *sb)`                                                              | Null-terminate buffer, set overflow if needed.                                    | –                            |\n| Append character               | `void sb_putc(sb *sb, char c)`                                                      | Append single character.                                                          | –                            |\n| Append bytes                   | `void sb_append_bytes(sb *sb, char *src, int len)`                                  | Append `len` bytes from a buffer.                                                 | –                            |\n| Append C string                | `int sb_append_cstr(sb *sb, char *s)`                                               | Append null-terminated string.                                                    | Number of bytes appended     |\n| Append spaces                  | `void sb_append_spaces(sb *sb, int count)`                                          | Append `count` space characters.                                                  | –                            |\n| Append unsigned long           | `int sb_append_ulong(sb *sb, unsigned long v, int width, sb_pad_mode pad)`          | Append unsigned integer with optional width and padding.                          | Number of characters written |\n| Append signed long             | `int sb_append_long(sb *sb, long v, int width, sb_pad_mode pad)`                    | Append signed integer with optional width and padding.                            | Number of characters written |\n| Append float                   | `int sb_append_float(sb *sb, float x, int width, int precision, sb_pad_mode pad)`   | Append floating-point number with precision and optional padding.                 | Number of characters written |\n| Append double                  | `int sb_append_double(sb *sb, double x, int width, int precision, sb_pad_mode pad)` | Append double with precision and optional padding.                                | Number of characters written |\n| Compare SB to string           | `int sb_cmp(const sb *sb, const char *s)`                                           | Compare SB content to a C string. Returns 0 if equal, \u003c0 if sb \u003c s, \u003e0 if sb \u003e s. | Comparison result            |\n| Compare SB to string (up to n) | `int sb_ncmp(const sb *sb, const char *s, int n)`                                   | Compare SB content to first `n` chars of a C string.                              | Comparison result            |\n\n### Notes on `sb_printf`\n- **Supported format specifiers:**  \n  `%s` (string), `%d` (signed int), `%u` (unsigned int), `%f` (float/double), `%c` (char)\n- **Width \u0026 padding:**  \n  - `%5d` → right-padded  \n  - `%-5d` → left-padded  \n- **Precision:**  \n  - `%.2f` → 2 digits after decimal\n- Up to **8 arguments** supported (`sb_printf1` → `sb_printf8`).\n\n---\n\n## Run Example: nostdlib, freestsanding\n\nIn this repo you will find the \"examples/sb_win32_nostdlib.c\" with the corresponding \"build.bat\" file which\ncreates an executable only linked to \"kernel32\" and is not using the C standard library and executes the program afterwards.\n\n## \"nostdlib\" Motivation \u0026 Purpose\n\nnostdlib is a lightweight, minimalistic approach to C development that removes dependencies on the standard library. The motivation behind this project is to provide developers with greater control over their code by eliminating unnecessary overhead, reducing binary size, and enabling deployment in resource-constrained environments.\n\nMany modern development environments rely heavily on the standard library, which, while convenient, introduces unnecessary bloat, security risks, and unpredictable dependencies. nostdlib aims to give developers fine-grained control over memory management, execution flow, and system calls by working directly with the underlying platform.\n\n### Benefits\n\n#### Minimal overhead\nBy removing the standard library, nostdlib significantly reduces runtime overhead, allowing for faster execution and smaller binary sizes.\n\n#### Increased security\nStandard libraries often include unnecessary functions that increase the attack surface of an application. nostdlib mitigates security risks by removing unused and potentially vulnerable components.\n\n#### Reduced binary size\nWithout linking to the standard library, binaries are smaller, making them ideal for embedded systems, bootloaders, and operating systems where storage is limited.\n\n#### Enhanced performance\nDirect control over system calls and memory management leads to performance gains by eliminating abstraction layers imposed by standard libraries.\n\n#### Better portability\nBy relying only on fundamental system interfaces, nostdlib allows for easier porting across different platforms without worrying about standard library availability.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnickscha%2Fsb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnickscha%2Fsb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnickscha%2Fsb/lists"}