Просмотр исходного кода

Update standard functions

Include _s wrappers for most standard function calls.
master
TheoryOfNekomata 1 год назад
Родитель
Сommit
f11a8ff220
34 измененных файлов: 126 добавлений и 79 удалений
  1. +6
    -6
      CMakeLists.txt
  2. +4
    -3
      src/packages/asset-inv/main.c
  3. +3
    -3
      src/packages/config/IZ_config.c
  4. +2
    -1
      src/packages/config/IZ_config.h
  5. +1
    -1
      src/packages/game/IZ_app.c
  6. +1
    -0
      src/packages/game/IZ_app.h
  7. +3
    -3
      src/packages/game/IZ_app_config.c
  8. +1
    -0
      src/packages/game/IZ_app_config.h
  9. +2
    -2
      src/packages/game/input/IZ_joystick.c
  10. +1
    -0
      src/packages/game/input/IZ_joystick.h
  11. +2
    -2
      src/packages/game/input/IZ_keyboard.c
  12. +1
    -0
      src/packages/game/input/IZ_keyboard.h
  13. +2
    -2
      src/packages/game/input/IZ_midi.c
  14. +2
    -1
      src/packages/game/input/IZ_midi.h
  15. +13
    -12
      src/packages/game/input/input.test.c
  16. +1
    -1
      src/packages/game/output/video/IZ_video.c
  17. +1
    -0
      src/packages/game/output/video/IZ_video.h
  18. +0
    -18
      src/packages/game/util/IZ_midi.h
  19. +9
    -15
      src/packages/midi/IZ_midi.c
  20. +18
    -0
      src/packages/midi/IZ_midi.h
  21. +1
    -1
      src/packages/net/IZ_net_client.c
  22. +1
    -0
      src/packages/net/IZ_net_client.h
  23. +1
    -1
      src/packages/net/IZ_net_server.c
  24. +1
    -0
      src/packages/net/IZ_net_server.h
  25. +2
    -2
      src/packages/net/core/IZ_websocket.c
  26. +1
    -0
      src/packages/net/core/IZ_websocket.h
  27. +1
    -1
      src/packages/server/IZ_app.c
  28. +1
    -0
      src/packages/server/IZ_app.h
  29. +3
    -3
      src/packages/server/IZ_app_config.c
  30. +1
    -0
      src/packages/server/IZ_app_config.h
  31. +1
    -1
      src/packages/server/db/IZ_repo.c
  32. +1
    -0
      src/packages/server/db/IZ_repo.h
  33. +26
    -0
      src/packages/string/IZ_string.c
  34. +12
    -0
      src/packages/string/IZ_string.h

+ 6
- 6
CMakeLists.txt Просмотреть файл

@@ -119,11 +119,11 @@ add_executable(
src/packages/net/svc/IZ_wsclient.h
src/packages/log/IZ_log.c
src/packages/log/IZ_log.h
src/packages/game/util/IZ_midi.c
src/packages/game/util/IZ_midi.h
src/packages/midi/IZ_midi.c
src/packages/midi/IZ_midi.h
src/packages/net/core/IZ_websocket.h
src/packages/net/core/IZ_websocket.c
src/packages/net/IZ_net_client.c src/packages/net/IZ_net_client.h src/packages/game/IZ_app_net.c src/packages/game/IZ_app_net.h src/packages/game/IZ_app_video.c src/packages/game/IZ_app_video.h src/packages/game/IZ_subsystem.h src/packages/game/IZ_app_input.c src/packages/game/IZ_app_input.h src/packages/game/IZ_app_config.c src/packages/game/IZ_app_config.h src/packages/game/asset/IZ_asset.c src/packages/game/asset/IZ_asset.h)
src/packages/net/IZ_net_client.c src/packages/net/IZ_net_client.h src/packages/game/IZ_app_net.c src/packages/game/IZ_app_net.h src/packages/game/IZ_app_video.c src/packages/game/IZ_app_video.h src/packages/game/IZ_subsystem.h src/packages/game/IZ_app_input.c src/packages/game/IZ_app_input.h src/packages/game/IZ_app_config.c src/packages/game/IZ_app_config.h src/packages/game/asset/IZ_asset.c src/packages/game/asset/IZ_asset.h src/packages/string/IZ_string.c src/packages/string/IZ_string.h)

if (WIN32)
target_link_libraries(
@@ -188,8 +188,8 @@ add_executable(
src/packages/game/input/IZ_midi.h
src/packages/game/input/IZ_midi.c

src/packages/game/util/IZ_midi.c
src/packages/game/util/IZ_midi.h
src/packages/midi/IZ_midi.c
src/packages/midi/IZ_midi.h

src/packages/game/input/input.test.c
)
@@ -259,7 +259,7 @@ add_executable(
src/packages/server/db/IZ_repo.c
src/packages/server/db/IZ_repo.h
src/packages/server/IZ_subsystem.h
)
src/packages/string/IZ_string.c src/packages/string/IZ_string.h)

add_executable(
asset-inv


+ 4
- 3
src/packages/asset-inv/main.c Просмотреть файл

@@ -1,10 +1,11 @@
#include <stdio.h>
#include "minIni.h"
#include "../common/IZ_common.h"
#include "../string/IZ_string.h"

// #ifdef WIN64
#ifdef IZ_WIN64
#include <windows.h>
// #endif
#endif

i32 IZ_ReadAsset(const char* current_dir, const char* ini_filename) {
WIN32_FIND_DATA fd_file;
@@ -33,7 +34,7 @@ i32 IZ_ReadAsset(const char* current_dir, const char* ini_filename) {
}

char final_current_dir[2048];
memcpy(final_current_dir, current_dir, 2048);
IZ_memcpy(final_current_dir, 2048, current_dir, 2048);

u16 i = 0;
char c = current_dir[i];


+ 3
- 3
src/packages/config/IZ_config.c Просмотреть файл

@@ -123,13 +123,13 @@ void IZ_ConfigEnsureValidString(IZ_ConfigItem* item, const char* buffer) {
if (item->validator) {
IZ_ConfigLoadParamsStringValidator* validator = item->validator;
if (validator(buffer)) {
memcpy(item->dest, buffer, item->dest_size);
IZ_memcpy(item->dest, item->dest_size, buffer, item->dest_size);
return;
}
memcpy(item->dest, item->default_value, item->dest_size);
IZ_memcpy(item->dest, item->dest_size, item->default_value, item->dest_size);
return;
}
memcpy(item->dest, buffer, item->dest_size);
IZ_memcpy(item->dest, item->dest_size, buffer, item->dest_size);
}

void IZ_ConfigLoadString(IZ_ConfigItem* item, const char* config_path) {


+ 2
- 1
src/packages/config/IZ_config.h Просмотреть файл

@@ -5,6 +5,7 @@
#include <string.h>
#include <minIni.h>
#include "../common/IZ_common.h"
#include "../string/IZ_string.h"

typedef enum {
IZ_CONFIG_TYPE_VOID,
@@ -32,7 +33,7 @@ typedef struct {
void* dest;
} IZ_ConfigItem;

void IZ_ConfigGetDefaultPath(const char*, size_t);
void IZ_ConfigGetDefaultPath(char*, size_t);

const char* IZ_ConfigGetCommandlineOption(u8, const char*[], const char*);



+ 1
- 1
src/packages/game/IZ_app.c Просмотреть файл

@@ -32,7 +32,7 @@ IZ_AppInitializeResult IZ_AppInitialize(struct IZ_App* app, u8 argc, const char*
char config_path[128];
// TODO abstract command line args parsing
if ((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, "-c"))) {
memcpy(config_path, cmdline_buffer, 128);
IZ_memcpy(config_path, 128, cmdline_buffer, 128);
} else {
IZ_ConfigGetDefaultPath(config_path, 128);
}


+ 1
- 0
src/packages/game/IZ_app.h Просмотреть файл

@@ -9,6 +9,7 @@
#include "IZ_app_input.h"
#include "IZ_app_net.h"
#include "IZ_app_video.h"
#include "../string/IZ_string.h"

typedef enum {
IZ_APP_RESULT_INITIALIZATION_ERROR = -1,


+ 3
- 3
src/packages/game/IZ_app_config.c Просмотреть файл

@@ -1,12 +1,12 @@
#include "IZ_app_config.h"

void IZ_ConfigGetDefaultPath(const char* config_path, size_t string_size) {
void IZ_ConfigGetDefaultPath(char* config_path, size_t string_size) {
#ifdef IZ_DEBUG
const char* config_path_dir = SDL_GetBasePath();
#else
const char* config_path_dir = SDL_GetPrefPath("Modal Studios", IZ_APP_NAME);
#endif

memcpy(config_path, config_path_dir, string_size);
strcat(config_path, "config-game.ini");
IZ_memcpy(config_path, string_size, config_path_dir, 128);
IZ_strcat(config_path, string_size, "config-game.ini");
}

+ 1
- 0
src/packages/game/IZ_app_config.h Просмотреть файл

@@ -4,5 +4,6 @@
#include <SDL_filesystem.h>
#include "IZ_subsystem.h"
#include "../config/IZ_config.h"
#include "../string/IZ_string.h"

#endif

+ 2
- 2
src/packages/game/input/IZ_joystick.c Просмотреть файл

@@ -276,7 +276,7 @@ IZ_ProcedureResult IZ_JoystickInitializeConfig(IZ_JoystickState(* state)[IZ_PLAY
}

IZ_ProcedureResult IZ_JoystickInitialize(IZ_JoystickState(* state)[IZ_PLAYERS], const char* config_path, u8 argc, const char* argv[]) {
SDL_memcpy(state, &IZ_JOYSTICK_DEFAULT_STATE, sizeof(IZ_JoystickState) * IZ_PLAYERS);
IZ_memcpy(state, sizeof(IZ_JoystickState) * IZ_PLAYERS, &IZ_JOYSTICK_DEFAULT_STATE, sizeof(IZ_JoystickState) * IZ_PLAYERS);

// TODO query this file from the internet?
SDL_GameControllerAddMappingsFromFile("assets/gamecontrollerdb.txt");
@@ -299,7 +299,7 @@ IZ_ProcedureResult IZ_JoystickInitialize(IZ_JoystickState(* state)[IZ_PLAYERS],

(*state)[player_index].config.device_id = SDL_JoystickInstanceID((*state)[player_index].device);
SDL_GUID joystick_guid = SDL_JoystickGetGUID((*state)[player_index].device);
memcpy(&(*state)[player_index].config.guid, &joystick_guid, sizeof(SDL_GUID));
IZ_memcpy(&(*state)[player_index].config.guid, sizeof(SDL_GUID), &joystick_guid, sizeof(SDL_GUID));
//(*state)[player_index].config.guid = joystick_guid;

printf("[INPUT:JOYSTICK] Initialize event from GUID: ");


+ 1
- 0
src/packages/game/input/IZ_joystick.h Просмотреть файл

@@ -7,6 +7,7 @@
#include <SDL_events.h>
#include <minIni.h>
#include "../../config/IZ_config.h"
#include "../../string/IZ_string.h"
#include "IZ_action.h"

typedef u8 IZ_PadButton;


+ 2
- 2
src/packages/game/input/IZ_keyboard.c Просмотреть файл

@@ -4,7 +4,7 @@ static IZ_ConfigItem keyboard_config_items[IZ_PLAYERS * IZ_CONTROLS + 1];

void IZ_KeyboardSerializeControl(i32 value, char control[128]) {
const char* serialized = SDL_GetKeyName(value);
memcpy(control, serialized, 128);
IZ_memcpy(control, 128, serialized, 128);
}

i32 IZ_KeyboardDeserializeControl(const char* control) {
@@ -87,7 +87,7 @@ IZ_ProcedureResult IZ_KeyboardInitializeConfig(IZ_KeyboardState(* state)[IZ_PLAY
}

IZ_ProcedureResult IZ_KeyboardInitialize(IZ_KeyboardState(* state)[IZ_PLAYERS], const char* config_path, u8 argc, const char* argv[]) {
SDL_memcpy(state, &IZ_KEYBOARD_DEFAULT_STATE, sizeof(IZ_KeyboardState) * IZ_PLAYERS);
IZ_memcpy(state, sizeof(IZ_KeyboardState) * IZ_PLAYERS, &IZ_KEYBOARD_DEFAULT_STATE, sizeof(IZ_KeyboardState) * IZ_PLAYERS);
if (IZ_KeyboardInitializeConfig(state, config_path, argc, argv) < 0) {
return -2;
}


+ 1
- 0
src/packages/game/input/IZ_keyboard.h Просмотреть файл

@@ -6,6 +6,7 @@
#include <SDL_events.h>
#include <minIni.h>
#include "../../config/IZ_config.h"
#include "../../string/IZ_string.h"
#include "IZ_action.h"

typedef struct {


+ 2
- 2
src/packages/game/input/IZ_midi.c Просмотреть файл

@@ -8,7 +8,7 @@ bool IZ_MIDIInputIsValidChannel(u8 value) {

void IZ_MIDIInputSerializeControl(i32 value, char* control[128]) {
const char* serialized = IZ_MIDIGetNoteName(value);
memcpy(control, serialized, 128);
IZ_memcpy(control, 128, serialized, 128);
}

i32 IZ_MIDIInputDeserializeControl(const char* control) {
@@ -147,7 +147,7 @@ IZ_ProcedureResult IZ_MIDIInputInitialize(IZ_MIDIInputState(* state)[IZ_PLAYERS]
return -1;
}

SDL_memcpy(state, &IZ_MIDI_INPUT_DEFAULT_STATE, sizeof(IZ_MIDIInputState) * IZ_PLAYERS);
IZ_memcpy(state, sizeof(IZ_MIDIInputState) * IZ_PLAYERS, &IZ_MIDI_INPUT_DEFAULT_STATE, sizeof(IZ_MIDIInputState) * IZ_PLAYERS);
if (IZ_MIDIInputInitializeConfig(state, config_path, argc, argv) < 0) {
return -2;
}


+ 2
- 1
src/packages/game/input/IZ_midi.h Просмотреть файл

@@ -11,7 +11,8 @@

#include <minIni.h>
#include "../../config/IZ_config.h"
#include "../util/IZ_midi.h"
#include "../../midi/IZ_midi.h"
#include "../../string/IZ_string.h"
#include "IZ_action.h"

#define MIDI_EVENT_BUFFER_SIZE 1024


+ 13
- 12
src/packages/game/input/input.test.c Просмотреть файл

@@ -3,6 +3,7 @@
#include "../../../__mocks__/SDL_stdinc.mock.h"
#include "../../../__mocks__/minIni.mock.h"
#include "../../../__mocks__/portmidi.mock.h"
//#include "../../string/IZ_string.h"
#include "IZ_keyboard.h"
#include "IZ_joystick.h"
#include "IZ_midi.h"
@@ -20,9 +21,9 @@ spec("input") {
describe("Initialize") {
static IZ_JoystickState state[IZ_PLAYERS];

after_each() {
mock_reset(SDL_memcpy);
}
// after_each() {
// mock_reset(IZ_memcpy);
// }

after_each() {
mock_reset(SDL_NumJoysticks);
@@ -43,7 +44,7 @@ spec("input") {
it("sets initial state") {
IZ_JoystickInitialize(&state, "config-game.ini", 0, NULL);

check(mock_is_called(SDL_memcpy), "Initial state not loaded.");
// check(mock_is_called(IZ_memcpy), "Initial state not loaded.");
check(mock_is_called(SDL_NumJoysticks), "Connected joysticks not checked.");
}

@@ -395,9 +396,9 @@ spec("input") {
describe("Initialize") {
static IZ_KeyboardState state[IZ_PLAYERS] = {};

after_each() {
mock_reset(SDL_memcpy);
}
// after_each() {
// mock_reset(IZ_memcpy);
// }

after_each() {
mock_reset(ini_gets);
@@ -418,7 +419,7 @@ spec("input") {
it("sets initial state") {
IZ_KeyboardInitialize(&state, "config-game.ini", 0, NULL);

check(mock_is_called(SDL_memcpy), "Initial state not loaded.");
// check(mock_is_called(IZ_memcpy), "Initial state not loaded.");
}

it("calls load method") {
@@ -520,9 +521,9 @@ spec("input") {
describe("Initialize") {
static IZ_MIDIInputState state[IZ_PLAYERS];

after_each() {
mock_reset(SDL_memcpy);
}
// after_each() {
// mock_reset(IZ_memcpy);
// }

after_each() {
mock_reset(Pm_CountDevices);
@@ -551,7 +552,7 @@ spec("input") {
it("sets initial state") {
IZ_MIDIInputInitialize(&state, "config-game.ini", 0, NULL);

check(mock_is_called(SDL_memcpy), "Initial state not loaded.");
// check(mock_is_called(IZ_memcpy), "Initial state not loaded.");
check(mock_is_called(Pm_CountDevices), "Connected MIDI devices not checked.");
}



+ 1
- 1
src/packages/game/output/video/IZ_video.c Просмотреть файл

@@ -65,7 +65,7 @@ IZ_ProcedureResult IZ_VideoInitializeConfig(IZ_VideoState* state, const char* c
}

IZ_ProcedureResult IZ_VideoInitialize(IZ_VideoState* state, void* user_data, const char* config_path, u8 argc, const char* argv[]) {
SDL_memcpy(state, &IZ_VIDEO_DEFAULT_STATE, sizeof(IZ_VideoState));
IZ_memcpy(state, sizeof(IZ_VideoState), &IZ_VIDEO_DEFAULT_STATE, sizeof(IZ_VideoState));
memset(state->active_sprites, 0, sizeof(IZ_SpriteSlot) * MAX_ACTIVE_SPRITES);
if (IZ_VideoInitializeConfig(state, config_path, argc, argv) < 0) {
return -2;


+ 1
- 0
src/packages/game/output/video/IZ_video.h Просмотреть файл

@@ -9,6 +9,7 @@
#include "../../../net/IZ_net_client.h"
#include "../../../config/IZ_config.h"
#include "../../../common/IZ_common.h"
#include "../../../string/IZ_string.h"
#include "../../geometry/IZ_vector2d.h"
#include "../../input/IZ_input.h"



+ 0
- 18
src/packages/game/util/IZ_midi.h Просмотреть файл

@@ -1,18 +0,0 @@
#ifndef IZ_UTIL_MIDI_H
#define IZ_UTIL_MIDI_H

#include <stdio.h>
#include <string.h>
#include "../../common/IZ_common.h"

typedef u8 IZ_MIDINote;

static const u8 IZ_MIDI_NOTE_ON = 0x90u;

static const u8 IZ_MIDI_NOTE_OFF = 0x80u;

char* IZ_MIDIGetNoteName(u8);

u8 IZ_MIDIGetNoteFromName(const char*);

#endif

src/packages/game/util/IZ_midi.c → src/packages/midi/IZ_midi.c Просмотреть файл

@@ -1,6 +1,6 @@
#include "IZ_midi.h"

char* IZ_MIDIGetNoteName(u8 midi_note) {
char* IZ_MIDIGetNoteName(unsigned char midi_note) {
static const char* pitch_names[] = {
"C",
"C#",
@@ -16,30 +16,24 @@ char* IZ_MIDIGetNoteName(u8 midi_note) {
"B"
};

const u8 pitch_class = midi_note % 12;
const u8 octave = midi_note / 12;
const unsigned char pitch_class = midi_note % 12;
const unsigned char octave = midi_note / 12;
static char note_name[8];
sprintf(note_name, "%s%u", pitch_names[pitch_class], octave);
return note_name;
}

u8 IZ_MIDIGetNoteFromName(const char* name) {
unsigned char IZ_MIDIGetNoteFromName(const char* name) {
char name_copy[8];
memcpy(name_copy, name, 8);
#ifdef IZ_WIN32
_strlwr_s(name_copy, 8);
#elif defined IZ_WIN64
_strlwr_s(name_copy, 8);
#else
_strlwr(name_copy);
#endif
IZ_memcpy(name_copy, 8, name, 8);
IZ_strlwr(name_copy, 8);

u8 octave;
unsigned char octave;
const char base_pitch_name[] = "c d ef g a b";

if (strlen(name_copy) == 2) {
octave = name_copy[1] - '0';
u8 pitch_index;
unsigned char pitch_index;
for (pitch_index = 0; pitch_index < 12; pitch_index += 1) {
if (base_pitch_name[pitch_index] == name_copy[0]) {
return (octave * 12) + pitch_index;
@@ -48,7 +42,7 @@ u8 IZ_MIDIGetNoteFromName(const char* name) {
return 255u; // invalid note value
}

u8 pitch_class;
unsigned char pitch_class;
octave = name_copy[2] - '0';
if (strstr(name_copy, "c#") || strstr(name_copy, "db")) {
pitch_class = 1;

+ 18
- 0
src/packages/midi/IZ_midi.h Просмотреть файл

@@ -0,0 +1,18 @@
#ifndef IZ_MIDI_MIDI_H
#define IZ_MIDI_MIDI_H

#include <stdio.h>
#include <string.h>
#include "../string/IZ_string.h"

typedef unsigned char IZ_MIDINote;

static const unsigned char IZ_MIDI_NOTE_ON = 0x90u;

static const unsigned char IZ_MIDI_NOTE_OFF = 0x80u;

char* IZ_MIDIGetNoteName(unsigned char);

unsigned char IZ_MIDIGetNoteFromName(const char*);

#endif

+ 1
- 1
src/packages/net/IZ_net_client.c Просмотреть файл

@@ -106,7 +106,7 @@ IZ_ProcedureResult IZ_NetClientInitialize(
if (!user_data) {
return -1;
}
memcpy(state, &IZ_NET_CLIENT_DEFAULT_STATE, sizeof(IZ_NetClientState));
IZ_memcpy(state, sizeof(IZ_NetClientState), &IZ_NET_CLIENT_DEFAULT_STATE, sizeof(IZ_NetClientState));
if (IZ_NetClientInitializeConfig(state, config_path, argc, argv) < 0) {
return -2;
}


+ 1
- 0
src/packages/net/IZ_net_client.h Просмотреть файл

@@ -6,6 +6,7 @@
#include "../config/IZ_config.h"
#include "../common/IZ_common.h"
#include "../game/input/IZ_action.h"
#include "../string/IZ_string.h"
#include "svc/IZ_wsclient.h"

typedef enum {


+ 1
- 1
src/packages/net/IZ_net_server.c Просмотреть файл

@@ -84,7 +84,7 @@ IZ_ProcedureResult IZ_NetServerInitialize(
if (!user_data) {
return -1;
}
memcpy_s(state, sizeof(IZ_NetServerState), &IZ_NET_SERVER_DEFAULT_STATE, sizeof(IZ_NetServerState));
IZ_memcpy(state, sizeof(IZ_NetServerState), &IZ_NET_SERVER_DEFAULT_STATE, sizeof(IZ_NetServerState));
if (IZ_NetServerInitializeConfig(state, config_path, argc, argv) < 0) {
return -2;
}


+ 1
- 0
src/packages/net/IZ_net_server.h Просмотреть файл

@@ -4,6 +4,7 @@
#include <minIni.h>
#include "../config/IZ_config.h"
#include "../common/IZ_common.h"
#include "../string/IZ_string.h"
#include "core/IZ_websocket.h"
#include "svc/IZ_wsserver.h"



+ 2
- 2
src/packages/net/core/IZ_websocket.c Просмотреть файл

@@ -39,7 +39,7 @@ IZ_ProcedureResult IZ_WebsocketCreateBinaryMessage(struct lws* wsi, IZ_Websocket
amsg->final = (u8) lws_is_final_fragment(wsi);
amsg->binary = true;
amsg->len = len;
memcpy((char*) amsg->payload + LWS_PRE, in, len);
IZ_memcpy((char*) amsg->payload + LWS_PRE, len, in, len);
return 0;
}

@@ -54,6 +54,6 @@ IZ_ProcedureResult IZ_WebsocketCreateTextMessage(struct lws* wsi, IZ_WebsocketMe
amsg->final = (u8) lws_is_final_fragment(wsi);
amsg->binary = false;
amsg->len = len;
memcpy((char*) amsg->payload + LWS_PRE, in, len);
IZ_memcpy((char*) amsg->payload + LWS_PRE, len, in, len);
return 0;
}

+ 1
- 0
src/packages/net/core/IZ_websocket.h Просмотреть файл

@@ -3,6 +3,7 @@

#include "libwebsockets.h"
#include "../../common/IZ_common.h"
#include "../../string/IZ_string.h"

#define NETWORK_PROTOCOL "izanagi-networking"
#define RING_COUNT 32


+ 1
- 1
src/packages/server/IZ_app.c Просмотреть файл

@@ -19,7 +19,7 @@ IZ_ProcedureResult IZ_AppInitialize(IZ_App *app, u8 argc, const char **argv) {
char config_path[128];
// TODO abstract command line args parsing
if ((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, "-c"))) {
memcpy_s(config_path, 128, cmdline_buffer, 128);
IZ_memcpy(config_path, 128, cmdline_buffer, 128);
} else {
IZ_ConfigGetDefaultPath(config_path, 128);
}


+ 1
- 0
src/packages/server/IZ_app.h Просмотреть файл

@@ -6,6 +6,7 @@
#include "../common/IZ_common.h"
#include "../net/IZ_net_server.h"
#include "../log/IZ_log.h"
#include "../string/IZ_string.h"
#include "db/IZ_repo.h"
#include "IZ_app_config.h"



+ 3
- 3
src/packages/server/IZ_app_config.c Просмотреть файл

@@ -1,12 +1,12 @@
#include "IZ_app_config.h"

void IZ_ConfigGetDefaultPath(const char* config_path, size_t string_size) {
void IZ_ConfigGetDefaultPath(char* config_path, size_t string_size) {
#ifdef IZ_DEBUG
const char* config_path_dir = SDL_GetBasePath();
#else
const char* config_path_dir = SDL_GetPrefPath("Modal Studios", IZ_APP_NAME);
#endif

memcpy_s(config_path, string_size, config_path_dir, 128);
strcat_s(config_path, string_size, "config-server.ini");
IZ_memcpy(config_path, string_size, config_path_dir, 128);
IZ_strcat(config_path, string_size, "config-server.ini");
}

+ 1
- 0
src/packages/server/IZ_app_config.h Просмотреть файл

@@ -3,6 +3,7 @@

#include <SDL_filesystem.h>
#include "../config/IZ_config.h"
#include "../string/IZ_string.h"
#include "IZ_subsystem.h"

#endif

+ 1
- 1
src/packages/server/db/IZ_repo.c Просмотреть файл

@@ -36,7 +36,7 @@ IZ_ProcedureResult IZ_RepoInitializeConfig(IZ_RepoState* state, const char* conf
}

IZ_ProcedureResult IZ_RepoInitialize(IZ_RepoState* state, const char* config_path, u8 argc, const char* argv[]) {
memcpy_s(state, sizeof(IZ_RepoState), &IZ_REPO_DEFAULT_STATE, sizeof(IZ_RepoState));
IZ_memcpy(state, sizeof(IZ_RepoState), &IZ_REPO_DEFAULT_STATE, sizeof(IZ_RepoState));
if (IZ_RepoInitializeConfig(state, config_path, argc, argv) < 0) {
return -2;
}


+ 1
- 0
src/packages/server/db/IZ_repo.h Просмотреть файл

@@ -6,6 +6,7 @@
#include <string.h>
#include "../../common/IZ_common.h"
#include "../../config/IZ_config.h"
#include "../../string/IZ_string.h"

typedef struct {
char path[64];


+ 26
- 0
src/packages/string/IZ_string.c Просмотреть файл

@@ -0,0 +1,26 @@
#include "IZ_string.h"

errno_t IZ_memcpy(void* const dest, const rsize_t dest_size, const void* const source, const rsize_t source_size) {
#if defined IZ_WIN64

return memcpy_s(dest, dest_size, source, source_size);
#else
return memcpy(dest, source, dest_size - 1);
#endif
}

errno_t IZ_strcat(char* dest, rsize_t source_size, const char* source) {
#if defined IZ_WIN64
return strcat_s(dest, source_size, source);
#else
return strcat(dest, source);
#endif
}

errno_t IZ_strlwr(char* str, rsize_t str_size) {
#if defined IZ_WIN64
return _strlwr_s(str, str_size);
#else
return _strlwr(str);
#endif
}

+ 12
- 0
src/packages/string/IZ_string.h Просмотреть файл

@@ -0,0 +1,12 @@
#ifndef IZ_STRING_H
#define IZ_STRING_H

#include <string.h>

errno_t IZ_memcpy(void*, rsize_t, const void*, rsize_t);

errno_t IZ_strcat(char*, rsize_t, const char*);

errno_t IZ_strlwr(char*, rsize_t);

#endif

Загрузка…
Отмена
Сохранить