Clean up file handling

FossilOrigin-Name: 3d55e077f74fc1c036e856cc4fdf0ae3c308c58f7d37eb9392f1a15f10cc237d
This commit is contained in:
Jonathan Schleifer 2025-03-05 21:29:54 +00:00
parent c6eebefd77
commit ab582d3745
14 changed files with 278 additions and 231 deletions

View file

@ -100,38 +100,6 @@ gp() // useful for global buffers that need to be initialisation order
///////////////////////// misc tools ///////////////////////
char *
path(char *s)
{
for (char *t = s; t = strpbrk(t, "/\\"); *t++ = PATHDIV)
;
return s;
};
char *
loadfile(char *fn, int *size)
{
FILE *f = fopen(fn, "rb");
if (!f)
return NULL;
fseek(f, 0, SEEK_END);
int len = ftell(f);
fseek(f, 0, SEEK_SET);
char *buf = (char *)malloc(len + 1);
if (!buf)
return NULL;
buf[len] = 0;
size_t rlen = fread(buf, 1, len, f);
fclose(f);
if (len != rlen || len <= 0) {
free(buf);
return NULL;
};
if (size != NULL)
*size = len;
return buf;
};
void
endianswap(
void *memory, int stride, int length) // little indians as storage format