1
0
Fork 0
forked from fun/fun

Tons of refactoring and some fixes and enhancements... ;)

This commit is contained in:
Johannes Findeisen 2025-09-15 06:31:32 +02:00
commit 13919ad87d
82 changed files with 1775 additions and 1382 deletions

31
src/builtins_io.c Normal file
View file

@ -0,0 +1,31 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* File I/O helpers: return malloc'd buffers or status ints */
char *bio_read_file_strdup(const char *path) {
if (!path) return strdup("");
FILE *f = fopen(path, "rb");
if (!f) return strdup("");
if (fseek(f, 0, SEEK_END) != 0) { fclose(f); return strdup(""); }
long sz = ftell(f);
if (sz < 0) { fclose(f); return strdup(""); }
rewind(f);
char *buf = (char*)malloc((size_t)sz + 1);
if (!buf) { fclose(f); return strdup(""); }
size_t n = fread(buf, 1, (size_t)sz, f);
fclose(f);
buf[n] = '\0';
return buf;
}
int bio_write_file(const char *path, const char *data, size_t len) {
if (!path) return 0;
FILE *f = fopen(path, "wb");
if (!f) return 0;
if (!data) data = "";
int ok = (fwrite(data, 1, len, f) == len);
fclose(f);
return ok;
}