| git.druid.rocks | index | druid520 | mp | src/ | mpx.h |
src/mpx.h
#ifndef MPX_H
#define MPX_H
#include <stdio.h>
#include <sys/types.h>
/* generously sized for a large, complex config (many per-package
* sections, deep dependency webs meaning many packages worth of
* TARGET_ / JOBS / MICROARCH / SANDBOX overrides in one mpx.conf, now
* potentially spread across a base file plus IMPORT=-pulled-in ones,
* see conf.c extractsection) rather than exactly right-sized: static
* storage, not stack, so the cost of headroom is a few hundred KB of
* bss, not a real constraint, and getting a size limit wrong fails
* either loudly (readfile truncation detection) or not at all, never
* silently corrupts data either way. */
#define MAXFILE (1024L * 1024L)
#define MAXKV 256
#define MAXKEY 32
#define MAXVAL 512
#define MAXPATH 1024
struct kv
{
char key[MAXKEY];
char val[MAXVAL];
};
/* util.c -- base helpers other files depend on. */
/* die() always exit()s, but mpx stays pure C89 (must build clean on
* tcc/gcc/clang alike) -- no __attribute__((noreturn)), a GNU/Clang
* extension. -fanalyzer therefore can't see that die() never returns,
* and flags a resource (fd, etc.) used after a die()'d branch as
* "possibly invalid" on a fall-through path that never actually
* happens: every such call site adds its own explicit "return;"
* immediately after die() to close that path off in plain, portable
* C89 instead. */
void die(const char* msg);
long pathfits(const char* a, const char* b);
long readfile(const char* path, char* buf, long max);
long writefile(const char* path, const char* buf, long n);
void setflags(const char* name, const char* extra);
void setxenv(const char* name, const char* val);
void setpath(const char* name, const char* extra);
const char* argval(int argc, char** argv, const char* name);
/* append str at *off in dst (max bytes total, NUL included); 0 on
* overflow (nothing written by this call), 1 on success -- the
* format-free replacement for the snprintf("%s...") joins whose length
* guards -Wformat-truncation cannot prove through a helper call on
* some toolchains. */
long bufcat(char* dst, size_t max, size_t* off, const char* str);
/* dst = "a/b" via bufcat; 0 if it doesn't fit. */
long pathjoin(char* dst, size_t max, const char* a, const char* b);
/* conf.c -- /etc/mpx.conf parsing. */
long parseconf(const char* buf, long n, struct kv* kv, long max);
const char* kvget(struct kv* kv, long nkv, const char* key);
long extractsection(const char* buf, long n, const char* pkgname, char* out, long outmax);
long expand_imports(const char* buf, long n, char* out, long outmax);
/* fstree.c -- filesystem-tree operations. */
void copyfile(const char* src, const char* dst);
void copytree(const char* src, const char* dst);
void rmtree(const char* path);
void walktree(const char* base, const char* rel, FILE* out, dev_t basedev,
int has_exclude, dev_t excldev, ino_t exclino);
/* sandbox.c -- Linux-only network+mount namespace isolation. */
#ifdef __linux__
void setup_sandbox(const char* stagedir, const char* prefix);
#endif
/* stage.c / runsh.c -- backend commands. */
void cmd_stage(int argc, char** argv);
void cmd_unstage(int argc, char** argv);
void cmd_runsh(int argc, char** argv);
void cmd_snapshot(int argc, char** argv);
/* merge.c -- folds a manifest's files from one prefix onto another. */
void cmd_merge(int argc, char** argv);
/* version.c -- reports MP_BUILD_* (buildinfo.h, generated by mk/b.sh). */
void cmd_version(int argc, char** argv);
/* mpx.c -- CLI plumbing, called from stage.c/runsh.c on bad usage. */
void badusage(const char* prog, const char* syntax);
#endif