#include #include #include #include #include "moonbit.h" static char *to_cstr(moonbit_bytes_t b) { int32_t n = Moonbit_array_length(b); char *s = (char *)malloc((size_t)n + 1); if (!s) abort(); memcpy(s, b, (size_t)n); s[n] = 0; return s; } static moonbit_bytes_t from_buf(const char *buf, size_t len) { moonbit_bytes_t out = moonbit_make_bytes((int32_t)len, 0); if (len) memcpy(out, buf, len); return out; } moonbit_bytes_t orbit_getenv(moonbit_bytes_t name) { char *n = to_cstr(name); const char *v = getenv(n); free(n); if (!v) return from_buf("", 0); return from_buf(v, strlen(v)); } void orbit_exit(int32_t code) { fflush(stdout); exit(code); } int32_t orbit_symlink(moonbit_bytes_t target, moonbit_bytes_t linkpath) { char *t = to_cstr(target); char *l = to_cstr(linkpath); unlink(l); int rc = symlink(t, l); free(t); free(l); return rc; } void orbit_print_err(moonbit_bytes_t msg) { char *m = to_cstr(msg); fputs(m, stderr); fflush(stderr); free(m); }