From 402106d4fc637bdda3f3b75f190a6b9335fc99d0 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Sun, 25 Feb 2024 03:21:44 +0100 Subject: [PATCH] replaced glib function calls to g_file_get_contents() --- src/game_bd/bd_caveset.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/game_bd/bd_caveset.c b/src/game_bd/bd_caveset.c index 36b82a5e..50598fb7 100644 --- a/src/game_bd/bd_caveset.c +++ b/src/game_bd/bd_caveset.c @@ -504,12 +504,11 @@ static void caveset_name_set_from_filename(char *filename) */ boolean gd_caveset_load_from_file(char *filename) { - GError *error = NULL; gsize length; char *buf; - boolean read; List *new_caveset; struct stat st; + File *file; if (stat(filename, &st) != 0) { @@ -525,12 +524,22 @@ boolean gd_caveset_load_from_file(char *filename) return FALSE; } - read = g_file_get_contents (filename, &buf, &length, &error); - if (!read) + if (!(file = openFile(filename, MODE_READ))) { - Warn("%s", error->message); + Warn("cannot open file '%s'", filename); - g_error_free(error); + return FALSE; + } + + buf = checked_malloc(st.st_size + 1); + length = readFile(file, buf, 1, st.st_size); + buf[length] = '\0'; + + closeFile(file); + + if (length < st.st_size) + { + Warn("cannot read file '%s'", filename); return FALSE; } -- 2.34.1