{"id":20323643,"url":"https://github.com/ratchov/snfmt","last_synced_at":"2026-06-07T11:32:06.664Z","repository":{"id":247767869,"uuid":"823503770","full_name":"ratchov/snfmt","owner":"ratchov","description":"snprintf extention with custom formatting functions","archived":false,"fork":false,"pushed_at":"2024-12-17T06:16:28.000Z","size":83,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-04T10:16:29.101Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ratchov.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-07-03T06:53:30.000Z","updated_at":"2024-12-17T06:16:32.000Z","dependencies_parsed_at":"2024-12-10T14:47:27.822Z","dependency_job_id":null,"html_url":"https://github.com/ratchov/snfmt","commit_stats":null,"previous_names":["ratchov/snfmt"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ratchov/snfmt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ratchov%2Fsnfmt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ratchov%2Fsnfmt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ratchov%2Fsnfmt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ratchov%2Fsnfmt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ratchov","download_url":"https://codeload.github.com/ratchov/snfmt/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ratchov%2Fsnfmt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27451401,"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-12-02T02:00:06.387Z","response_time":54,"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":[],"created_at":"2024-11-14T19:29:05.912Z","updated_at":"2025-12-02T11:04:37.458Z","avatar_url":"https://github.com/ratchov.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# snfmt - user-defined conversions for snprintf()\n\n## Description\n\nThe `snfmt()` function formats strings by calling `snprintf()`, but\nallows the caller to define additional conversions. For each occurrence of\nan user-defined conversion in the format string, `snfmt()` invokes the\nuser-provided call-back function that implements the conversions.\n\nExample:\n\n        snfmt(myfunc, buf, size, \"blob = {hexdump:%p,%zu}\", blob, sizeof(blob));\n\nThe user-defined conversions in the format strings are between curly brackets.\nThey are composed by a name, and an optional colon followed by a comma-separated\nlist of `%`-based specifiers that match `snfmt()` variadic arguments. This\nsyntax makes `snfmt()` format strings work with `snprintf()` as well, allowing\ncompilers to report format string errors.\n\nThe call-back function is passed as the first `snfmt()` argument. It is\ndefined as follows:\n\n        union snfmt_arg {\n                long long i;\n                unsigned long long u;\n                double f;\n                const char *s;\n                void *p;\n        };\n\n        int myfunc(char *buf, size_t size, const char *fmt, union snfmt_arg *arg);\n\nThe `arg` array contains the values fetched from the `snfmt()` variadic\nargument list, promoted to above types. They correspond to the specifiers list\nin the curly brackets. The `fmt` string is set to the string between curly\nbrackets with the flags and modifiers removed (ex. `%08llx` is replaced\nby `%x`). The `fmt` string will be used by `myfunc` to determine the conversion\nto perform; if no conversion could be performed, it should return -1, informing\n`snfmt()` to call `snprintf()` instead.\n\n`snfmt()` and the call-back function write at most `size - 1` characters\nto `buf`, followed by a terminating 0. If `size` is zero, no characters are\nwritten. The functions return the number of bytes that would have been output\nif `size` was unlimited.\n\n## Limitations\n\nArgument reordering (a.k.a `\u003cnumber\u003e$` immediately after the `%` character) is\nnot supported.\n\nNon-standard `%`-specifiers are not supported (ex. `%D`, `%O`, `%C`, `%S` and\nprobably others).\n\nIf `snfmt()` fails to parse the format string (syntax error or unsupported\n`%`-conversion specifier), the output string is truncated, and the size of\nthe truncated string is returned.\n\nThe size of user-defined conversions is limited to 64 characters. User-defined\nconversions may have at most 8 arguments.\n\n## Example\n\nExample (pseudo-code) of typical use:\n\n        int debug_fmt(char *buf, size_t size, const char *fmt, union snfmt_arg *args)\n        {\n                if (strcmp(fmt, \"hexdump:%p,%u\") == 0) {\n                        /* convert using args[0].p and args[1].u */\n                } else if (...) {\n                        ...\n                } else\n                        return -1;\n        }\n\n        void debug(const char *fmt, ...)\n        {\n                va_list ap;\n                char buf[256];\n\n                va_start(ap, fmt);\n                snfmt_va(debug_fmt, buf, sizeof(buf), fmt, ap);\n                va_end(ap);\n\n                fputs(buf, stderr);\n        }\n\n        int main(void)\n        {\n                ...\n                debug(\"x = %d, blob = {hexdump:%p,%zu}\\n\", x, blob, sizeof(blob));\n                ...\n        }\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fratchov%2Fsnfmt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fratchov%2Fsnfmt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fratchov%2Fsnfmt/lists"}