implements inner function definition in function condition

This commit is contained in:
Alexander Acker 2024-10-08 12:59:07 +02:00
parent b7f11d1fc2
commit 2fefd8c04f
3 changed files with 58 additions and 9 deletions

View file

@ -39,7 +39,7 @@ int tokenize_all(StringView source, DynamicArray* a)
char* load_file_string(StringView path)
{
FILE* stream = fopen(path.source, "r");
FILE* stream = fopen(path.source, "rb");
if (stream == NULL) {
fprintf(stderr, "Fatal Error: Failed to open file at %*s\n", (int) path.length, path.source);
return NULL;
@ -56,7 +56,10 @@ char* load_file_string(StringView path)
return NULL;
}
rewind(stream);
if (fseek(stream, 0, SEEK_SET)) {
perror("fseek");
return NULL;
}
char* buffer = malloc(length + 1);
if (buffer == NULL) {
@ -64,9 +67,10 @@ char* load_file_string(StringView path)
return NULL;
}
size_t objects_read = fread(buffer, length, 1, stream);
if (objects_read != 1) {
size_t objects_read = fread(buffer, 1, length, stream);
if (objects_read != length) {
fprintf(stderr, "Fatal Error: Failed read %li bytes from script file, got only %li\n", length, objects_read);
;
free(buffer);
return NULL;
}