romele / git-trace public
62 commits · 1 branch · 1 tag · 1 contributor (top: Romele) · first commit 3d ago · last push 11m ago
src/util.h
#ifndef GT_UTIL_H #define GT_UTIL_H #include <stddef.h> void die(const char *msg); void *xmalloc(size_t n); void *xrealloc(void *p, size_t n); char *xstrdup(const char *s); int starts_with(const char *s, const char *prefix); /* tiny glob: '*' matches any run incl. '/', '?' one char. 1 = match */ int gt_glob(const char *pat, const char *s); int ends_with(const char *s, const char *suffix); /* malloc'd, %-decoded; stops at '?'/fragment handled by caller */ char *url_decode(const char *s, size_t len); /* malloc'd HTML-escaped copy of s[0..len) */ char *html_escape(const char *s, size_t len); /* growable byte buffer */ struct buf { char *data; size_t len, cap; }; void buf_init(struct buf *b); void buf_put(struct buf *b, const void *p, size_t n); void buf_puts(struct buf *b, const char *s); void buf_printf(struct buf *b, const char *fmt, ...); void buf_put_urlenc(struct buf *b, const char *s, int keep_slash); void buf_put_escaped(struct buf *b, const char *s, size_t n); void buf_free(struct buf *b); const char *status_text(int code); int mkdir_p(const char *path); /* detached background helper: double-fork + setsid + re-exec of the * current binary as `git-trace <subcmd>`. Only async-signal-safe * calls between fork and exec, so it is safe from server threads and * hooks; the intermediate child is reaped immediately — no zombies. */ void gt_spawn_task(const char *subcmd); /* same, plus one extra argv word passed verbatim to the subcommand */ void gt_spawn_task_arg(const char *subcmd, const char *arg); #endif