fix(server): fixed check for operating system

This commit is contained in:
Mineplay 2025-12-21 20:39:41 +01:00
parent b1f9b9acb2
commit fe7fea1c94
5 changed files with 18 additions and 18 deletions

View file

@ -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
*/

View file

@ -9,7 +9,7 @@
#ifndef COSMS_CORE_SERVER
#define COSMS_CORE_SERVER
#if defined(__GNUC__)
#if defined(__linux__)
#include <arpa/inet.h>
#elif defined(_WIN32)
#include <winsock2.h>
@ -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;

View file

@ -12,7 +12,7 @@
#include <stdint.h>
#include <limits.h>
#if defined(__GNUC__)
#if defined(__linux__)
#define _FILE_OFFSET_BITS_ 64
#include <unistd.h>
@ -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:

View file

@ -8,7 +8,7 @@
*/
#include "cosms-core/networking/server.h"
#if defined(__GNUC__)
#if defined(__linux__)
#include <unistd.h>
#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;

View file

@ -13,7 +13,7 @@
#include <stdlib.h>
#include <string.h>
#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