diff options
| author | Onur Gündüz <ogunduz@gmail.com> | 2026-06-20 20:10:56 +0200 |
|---|---|---|
| committer | Onur Gündüz <ogunduz@gmail.com> | 2026-06-21 05:57:19 +0200 |
| commit | 6b969d25ce136eaf695222bd1a10bff1ecac0220 (patch) | |
| tree | c23afb50c28b9deaddae5c6526a74ee11cf2d865 /tools/server/util.h | |
| parent | d4bdb8dae753462f621507d5fc3582e0e53da35c (diff) | |
| download | ffwd-6b969d25ce136eaf695222bd1a10bff1ecac0220.tar.gz ffwd-6b969d25ce136eaf695222bd1a10bff1ecac0220.zip | |
all: split Makefile and reorg library/tools
Diffstat (limited to 'tools/server/util.h')
| -rw-r--r-- | tools/server/util.h | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tools/server/util.h b/tools/server/util.h new file mode 100644 index 0000000..3175cd0 --- /dev/null +++ b/tools/server/util.h @@ -0,0 +1,36 @@ +#ifndef FFWD_SERVER_UTIL_H +#define FFWD_SERVER_UTIL_H + +#include <stdint.h> +#include <stddef.h> + +/* Die-on-OOM allocation, monotonic clocks, and timestamped logging shared by + * the ffwd-server translation units. The x* allocators abort the process on + * failure rather than returning NULL, so callers never null-check them; the + * attributes below carry that contract across translation-unit boundaries so + * the static analyzer does not flag the (correctly) unchecked uses. */ + +#if defined(__GNUC__) || defined(__clang__) +# define SERVER_NORETURN __attribute__((noreturn)) +# define SERVER_RETURNS_NONNULL __attribute__((returns_nonnull)) +#else +# define SERVER_NORETURN +# define SERVER_RETURNS_NONNULL +#endif + +SERVER_NORETURN void die_oom(void); + +SERVER_RETURNS_NONNULL void *xmalloc(size_t n); +SERVER_RETURNS_NONNULL void *xcalloc(size_t n, size_t sz); +SERVER_RETURNS_NONNULL void *xrealloc(void *p, size_t n); +SERVER_RETURNS_NONNULL char *xstrdup(const char *s); +SERVER_RETURNS_NONNULL char *xstrndup(const char *s, size_t n); + +uint64_t mstime(void); +uint64_t nstime(void); +double ns_to_ms(uint64_t ns); + +/* printf-style line logger: timestamp prefix, newline appended, to stderr. */ +void server_log(const char *fmt, ...) __attribute__((format(printf, 1, 2))); + +#endif /* FFWD_SERVER_UTIL_H */ |
