From fe7fea1c948c04b103ce02a5d15a878b31558631 Mon Sep 17 00:00:00 2001 From: Mineplay Date: Sun, 21 Dec 2025 20:39:41 +0100 Subject: [PATCH] fix(server): fixed check for operating system --- include/cosms-core/file.h | 6 +++--- include/cosms-core/networking/server.h | 4 ++-- src/file.c | 18 +++++++++--------- src/networking/server.c | 6 +++--- tests/unit/file.c | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/include/cosms-core/file.h b/include/cosms-core/file.h index d91ba9e..2d68110 100644 --- a/include/cosms-core/file.h +++ b/include/cosms-core/file.h @@ -38,7 +38,7 @@ typedef enum { struct cosms_core_file { int mode; - #if defined(__GNUC__) + #if defined(__linux__) int native_file; #elif defined(_WIN32) HANDLE native_file; @@ -50,7 +50,7 @@ struct cosms_core_file { * * @param file Pointer to file struct (must not be NULL) * @param path to the file to open - * @param mode to open the file in (read, write, apped, create or a combination of these) + * @param mode to open the file in (read, write, append, create or a combination of these) * @return COSMS_CORE_FILE_OK on success, or a negative error code */ CosmsCoreFileError cosms_core_file_open(struct cosms_core_file *file, const char *path, int mode); @@ -65,7 +65,7 @@ CosmsCoreFileError cosms_core_file_close(struct cosms_core_file *file); /** * @brief Gets the size of an opened file. * - * @param file Pointer to file struct that has been opned (must not be NULL) + * @param file Pointer to file struct that has been opened (must not be NULL) * @param size Pointer to the variable to store the size in (must not be NULL) * @return COSMS_CORE_FILE_OK on success, or a negative error code */ diff --git a/include/cosms-core/networking/server.h b/include/cosms-core/networking/server.h index 5ce943b..6873339 100644 --- a/include/cosms-core/networking/server.h +++ b/include/cosms-core/networking/server.h @@ -9,7 +9,7 @@ #ifndef COSMS_CORE_SERVER #define COSMS_CORE_SERVER -#if defined(__GNUC__) +#if defined(__linux__) #include #elif defined(_WIN32) #include @@ -26,7 +26,7 @@ struct cosms_core_server { unsigned short port, domain; int type; - #if defined(__GNUC__) + #if defined(__linux__) int listening_socket; #elif defined(_WIN32) SOCKET listening_socket; diff --git a/src/file.c b/src/file.c index aefaa3f..5f80269 100644 --- a/src/file.c +++ b/src/file.c @@ -12,7 +12,7 @@ #include #include -#if defined(__GNUC__) +#if defined(__linux__) #define _FILE_OFFSET_BITS_ 64 #include @@ -27,7 +27,7 @@ CosmsCoreFileError cosms_core_file_open(struct cosms_core_file *file, const char *path, int mode) { file->mode = mode; - #if defined(__GNUC__) + #if defined(__linux__) int flags = 0; if (mode & (COSMS_CORE_FILE_MODE_READ | COSMS_CORE_FILE_MODE_WRITE)) { flags |= O_RDWR; @@ -121,7 +121,7 @@ CosmsCoreFileError cosms_core_file_open(struct cosms_core_file *file, const char * @brief Closes an open file. */ CosmsCoreFileError cosms_core_file_close(struct cosms_core_file *file) { - #if defined(__GNUC__) + #if defined(__linux__) int error = close(file->native_file); if (error == -1) { if (errno == EBADF) { @@ -148,7 +148,7 @@ CosmsCoreFileError cosms_core_file_close(struct cosms_core_file *file) { * @brief Gets the size of an opened file. */ CosmsCoreFileError cosms_core_file_get_size(struct cosms_core_file *file, unsigned long long *size) { - #if defined(__GNUC__) + #if defined(__linux__) struct stat file_stat; if (fstat(file->native_file, &file_stat) != 0) { if (errno == EBADF) { @@ -184,7 +184,7 @@ CosmsCoreFileError cosms_core_file_read(struct cosms_core_file *file, char *buff return COSMS_CORE_FILE_INVALID_OPERATION; } - #if defined(__GNUC__) + #if defined(__linux__) int read_bytes = read(file->native_file, buffer, bytes_to_read); if (read_bytes == -1) { return COSMS_CORE_FILE_FAILED_TO_READ; @@ -211,7 +211,7 @@ CosmsCoreFileError cosms_core_file_read_all(struct cosms_core_file *file, char * return COSMS_CORE_FILE_INVALID_OPERATION; } - #if defined(__GNUC__) + #if defined(__linux__) struct stat file_stat; if (fstat(file->native_file, &file_stat) != 0) { return COSMS_CORE_FILE_COULD_NOT_READ_SIZE; @@ -293,7 +293,7 @@ CosmsCoreFileError cosms_core_file_write(struct cosms_core_file *file, char *buf return COSMS_CORE_FILE_INVALID_OPERATION; } - #if defined(__GNUC__) + #if defined(__linux__) int written_bytes = write(file->native_file, buffer, bytes_to_write); if (written_bytes == -1) { return COSMS_CORE_FILE_FAILED_TO_WRITE; @@ -323,7 +323,7 @@ CosmsCoreFileError cosms_core_file_write_all(struct cosms_core_file *file, char return COSMS_CORE_FILE_INVALID_OPERATION; } - #if defined(__GNUC__) + #if defined(__linux__) unsigned long long remaining_bytes = bytes_to_write; while (remaining_bytes != 0) { unsigned int current_bytes_to_write; @@ -372,7 +372,7 @@ CosmsCoreFileError cosms_core_file_write_all(struct cosms_core_file *file, char * @brief Deletes specified file from system. */ CosmsCoreFileError cosms_core_file_delete(const char *path) { - #if defined(__GNUC__) + #if defined(__linux__) if (unlink(path) == -1) { switch (errno) { case ENOENT: diff --git a/src/networking/server.c b/src/networking/server.c index 67285d3..d107912 100644 --- a/src/networking/server.c +++ b/src/networking/server.c @@ -8,7 +8,7 @@ */ #include "cosms-core/networking/server.h" -#if defined(__GNUC__) +#if defined(__linux__) #include #elif defined(_WIN32) static int cosms_core_server_initialized_winsock_instances = 0; @@ -27,7 +27,7 @@ CosmsCoreServerError cosms_core_server_create(struct cosms_core_server *new_serv address.sin_addr.s_addr = INADDR_ANY; address.sin_port = htons(port); - #if defined(__GNUC__) + #if defined(__linux__) new_server->listening_socket = socket(domain, type, 0); if (new_server->listening_socket == -1) { return COSMS_CORE_SERVER_FAILED_TO_CREATE_SOCKET; @@ -65,7 +65,7 @@ CosmsCoreServerError cosms_core_server_create(struct cosms_core_server *new_serv * @brief Stops and destroy's the server. */ CosmsCoreServerError cosms_core_server_destroy(struct cosms_core_server *current_server) { - #if defined(__GNUC__) + #if defined(__linux__) int result = close(current_server->listening_socket); if (result == -1) { return COSMS_CORE_SERVER_UNKNOWN_ERROR; diff --git a/tests/unit/file.c b/tests/unit/file.c index a523139..fb1d2e3 100644 --- a/tests/unit/file.c +++ b/tests/unit/file.c @@ -13,7 +13,7 @@ #include #include -#if defined (__GNUC__) +#if defined (__linux__) #define COSMS_CORE_FILE_TEST_INVALID_NATIVE_FILE -1 #elif defined(_WIN32) #define COSMS_CORE_FILE_TEST_INVALID_NATIVE_FILE NULL