Files
orbit/src/main/stub.c
T
nandiandClaude Haiku 5.5 ec21287549 Use moonbitlang/async for process and file IO
Process execution and file access go through @process and @fs. The spinner
is a background task in a task group, and the C stub keeps only getenv,
exit, isatty, symlink and stderr output. orbit info reads installed state
only, and it records and restores package descriptions. just install adds
Orbit's bin directory to ~/.bashrc once.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
2026-11-26 22:40:18 -08:00

52 lines
1.0 KiB
C

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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);
}