Artifact 9c7db28676550bc5a5913d5ee282920e65798bd77205869ae0ffa081dd629292:
- File
src/platform.c
— part of check-in
[6d70dcc76a]
at
2026-11-12 19:36:41
on branch trunk
— Phase 1: the config parser, the no-change run and the speed bench
suit check parses suit.conf strictly and prints a canonical dump. Any unknown kind or key, duplicate, cycle or dangling name rejects the whole file with its line number.
suit run compares a stamp against the files it names and exits without writing, allocating or printing when nothing changed.
suit bench times suit run against an empty program built the same way and against /usr/bin/true, interleaved, and fails the build when the no-change run costs more than 1 ms over the empty program or 1 MiB more memory. It measured 0.65 to 0.94 ms over, quiet and under load. A system binary starts 0.6 to 1.5 ms faster than any built binary on macOS, so it is shown for information and is not the baseline.
94 unit checks, 100 shell cases and a libFuzzer target for the parser. (user: dmestas, size: 1153) [annotate] [blame] [check-ins using]
#include "platform.h" #include <stdlib.h> #include <string.h> #include <unistd.h> #ifdef __APPLE__ #include <mach-o/dyld.h> #endif int64_t platform_mtime_sec(const struct stat *st) { #ifdef __APPLE__ return st->st_mtimespec.tv_sec; #else return st->st_mtim.tv_sec; #endif } int64_t platform_mtime_nsec(const struct stat *st) { #ifdef __APPLE__ return st->st_mtimespec.tv_nsec; #else return st->st_mtim.tv_nsec; #endif } uint64_t platform_peak_resident(const struct rusage *ru) { #ifdef __APPLE__ return (uint64_t)ru->ru_maxrss; // bytes #else return (uint64_t)ru->ru_maxrss * 1024; // kibibytes #endif } bool platform_self_path(char *buf, size_t cap) { #ifdef __APPLE__ char raw[4096]; uint32_t n = sizeof raw; if (_NSGetExecutablePath(raw, &n) != 0) return false; char *real = realpath(raw, nullptr); if (real == nullptr) return false; bool fits = strlen(real) < cap; if (fits) strcpy(buf, real); free(real); return fits; #else ssize_t n = readlink("/proc/self/exe", buf, cap - 1); if (n < 0 || (size_t)n >= cap - 1) return false; buf[n] = '\0'; return true; #endif }