interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / research / atemporal / at0 / model / at0_io.c

52 lines · 1959 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0
2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/* File input for the AT-0 candidate engine: reads a case file into memory and hands the
18 * bytes to the validator. This is the only component that touches the file system; the
19 * parser (at0_case.c) and every physics component work on bytes and structs alone. */
20#include "at0_model.h"
21#include <stdio.h>
22#include <stdlib.h>
23
24#define AT0_IO_FILE_CAP (4096 * 256) /* same byte budget as the parser's line table */
25
26at0_status at0_case_read_file(const char *path, at0_case *out)
27{
28 if (!path || !out) return AT0_ERR_ARGUMENT;
29 FILE *f = fopen(path, "rb");
30 if (!f) return AT0_ERR_IO;
31 size_t cap = 65536, len = 0;
32 uint8_t *buf = malloc(cap);
33 if (!buf) { fclose(f); return AT0_ERR_INTERNAL; }
34 for (;;) {
35 size_t n = fread(buf + len, 1, cap - len, f);
36 len += n;
37 if (n == 0) break;
38 if (len == cap) {
39 if (cap > (size_t)AT0_IO_FILE_CAP) { free(buf); fclose(f); return AT0_CASE_PARSE_ERROR; }
40 cap *= 2;
41 uint8_t *nb = realloc(buf, cap);
42 if (!nb) { free(buf); fclose(f); return AT0_ERR_INTERNAL; }
43 buf = nb;
44 }
45 }
46 int err = ferror(f);
47 fclose(f);
48 if (err) { free(buf); return AT0_ERR_IO; }
49 at0_status st = at0_case_parse(buf, len, out);
50 free(buf);
51 return st;
52}