fix(file): fixed tests and large file reading on linux

This commit is contained in:
Mineplay 2025-12-13 18:36:48 +01:00
parent 77f1518abc
commit 64535d0288
3 changed files with 11 additions and 8 deletions

View file

@ -10,8 +10,11 @@
#include <stdlib.h>
#include <stdint.h>
#include <limits.h>
#if defined(__GNUC__)
#define _FILE_OFFSET_BITS_ 64
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
@ -148,7 +151,7 @@ CosmsCoreFileError cosms_core_file_write(const char *path, const char *content,
if (override) {
file = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
} else {
file = open(path, O_WRONLY | O_APPEND);
file = open(path, O_WRONLY | O_CREAT | O_APPEND, 0644);
}
if (file == -1) {
@ -312,4 +315,4 @@ const char *cosms_core_file_error_string(CosmsCoreFileError error) {
default:
return NULL;
}
}
}

View file

@ -10,7 +10,7 @@
#define COSMS_CORE_TEST_SUCCESS(test_name) printf("[+] test %s completed successfully!\n", test_name);
#define COSMS_CORE_TEST_FAIL(test_name, error) printf("[-] test %s failed with error: %s\n", test_name, error)
inline bool cosms_core_test_assert(const char *test_name, bool expression, const char *error_message) {
static inline bool cosms_core_test_assert(const char *test_name, bool expression, const char *error_message) {
if (!expression) {
printf("[-] test %s failed with error: %s\n", test_name, error_message);
return false;
@ -19,4 +19,4 @@ inline bool cosms_core_test_assert(const char *test_name, bool expression, const
return true;
}
#endif
#endif

View file

@ -6,7 +6,7 @@
#include <string.h>
#include <stdlib.h>
void cosms_core_file_read_test() {
void cosms_core_file_read_test(void) {
COSMS_CORE_TEST_HEADER("file read");
const char *current_test_name = "reading small file";
@ -64,7 +64,7 @@ void cosms_core_file_read_test() {
free(file_buffer);
}
void cosms_core_file_write_test() {
void cosms_core_file_write_test(void) {
COSMS_CORE_TEST_HEADER("file write");
const char *current_test_name = "writting small file";
@ -147,7 +147,7 @@ void cosms_core_file_write_test() {
}
}
void cosms_core_file_delete_test() {
void cosms_core_file_delete_test(void) {
COSMS_CORE_TEST_HEADER("file delete");
const char *current_test_name = "deleting small file";
@ -189,4 +189,4 @@ void cosms_core_file_delete_test() {
if (cosms_core_test_assert(current_test_name, error == COSMS_CORE_FILE_NOT_FOUND, cosms_core_file_error_string(error))) {
COSMS_CORE_TEST_SUCCESS(current_test_name);
}
}
}