changeset 571:cba66f7d8a53

misc: various windows fixes
author David Demelier <markand@malikania.fr>
date Thu, 09 Mar 2023 22:33:46 +0100
parents aaf518c87628
children f7dcad94b7cf
files libmlk-core/mlk/core/alloc.c libmlk-core/mlk/core/err.c libmlk-core/mlk/core/sys.c libmlk-example/CMakeLists.txt libmlk-example/mlk/example/registry.c libmlk-rpg/mlk/rpg/map-loader.c libmlk-rpg/mlk/rpg/map-loader.h libmlk-rpg/mlk/rpg/tileset-loader.c libmlk-rpg/mlk/rpg/tileset-loader.h libmlk-ui/mlk/ui/debug.c libmlk-util/mlk/util/dir.c libmlk-util/mlk/util/fmemopen.c libmlk-util/mlk/util/openbsd/basename.c libmlk-util/mlk/util/openbsd/dirname.c libmlk-util/mlk/util/util.h
diffstat 15 files changed, 27 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/libmlk-core/mlk/core/alloc.c	Thu Mar 09 20:30:00 2023 +0100
+++ b/libmlk-core/mlk/core/alloc.c	Thu Mar 09 22:33:46 2023 +0100
@@ -18,6 +18,7 @@
 
 #include <assert.h>
 #include <errno.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
--- a/libmlk-core/mlk/core/err.c	Thu Mar 09 20:30:00 2023 +0100
+++ b/libmlk-core/mlk/core/err.c	Thu Mar 09 22:33:46 2023 +0100
@@ -26,7 +26,7 @@
 #define ERR_MAX         128
 #define DEFAULT_ERR     "no error"
 
-static _Thread_local char err[ERR_MAX] = DEFAULT_ERR;
+static MLK_THREAD_LOCAL char err[ERR_MAX] = DEFAULT_ERR;
 
 int
 mlk_errf(const char *fmt, ...)
--- a/libmlk-core/mlk/core/sys.c	Thu Mar 09 20:30:00 2023 +0100
+++ b/libmlk-core/mlk/core/sys.c	Thu Mar 09 22:33:46 2023 +0100
@@ -26,7 +26,7 @@
 #include <string.h>
 #include <limits.h>
 
-#if defined(MLK_OS_WINDOWS)
+#if defined(_WIN32)
 #       include <shlwapi.h>
 #       include <windows.h>
 #else
@@ -80,7 +80,7 @@
 	/* Kept for future use. */
 	(void)kind;
 
-	static _Thread_local char path[MLK_PATH_MAX];
+	static MLK_THREAD_LOCAL char path[MLK_PATH_MAX];
 	char *pref;
 
 	if ((pref = SDL_GetPrefPath(info.organization, info.name))) {
--- a/libmlk-example/CMakeLists.txt	Thu Mar 09 20:30:00 2023 +0100
+++ b/libmlk-example/CMakeLists.txt	Thu Mar 09 22:33:46 2023 +0100
@@ -67,7 +67,7 @@
 
 mlk_library(
 	NAME libmlk-example
-	SOURCES ${SOURCES}
+	SOURCES ${ASSETS} ${MAPS} ${TILESETS} ${SOURCES}
 	ASSETS ${ASSETS} ${maps} ${tilesets}
 	TYPE STATIC
 	LIBRARIES libmlk-rpg
--- a/libmlk-example/mlk/example/registry.c	Thu Mar 09 20:30:00 2023 +0100
+++ b/libmlk-example/mlk/example/registry.c	Thu Mar 09 22:33:46 2023 +0100
@@ -117,7 +117,7 @@
 		texture = &mlk_registry_images[images[i].index];
 
 		if (mlk_image_openmem(texture, images[i].data, images[i].datasz) < 0)
-			mlk_panic();
+			mlk_panicf("unable to open image: %s", mlk_err());
 	}
 }
 
@@ -132,7 +132,7 @@
 		sprite = &mlk_registry_sprites[textures[i].index];
 
 		if (mlk_image_openmem(texture, textures[i].data, textures[i].datasz) < 0)
-			mlk_panic();
+			mlk_panicf("unable to open image: %s", mlk_err());
 
 		if (textures[i].cellw == 0 || textures[i].cellh == 0) {
 			sprite->cellw = texture->w;
@@ -156,7 +156,7 @@
 		sound = &mlk_registry_sounds[sounds[i].index];
 
 		if (mlk_sound_openmem(sound, sounds[i].data, sounds[i].datasz) < 0)
-			mlk_panic();
+			mlk_panicf("unable to open sound: %s", mlk_err());
 	}
 }
 
@@ -169,7 +169,7 @@
 		music = &mlk_registry_music[musics[i].index];
 
 		if (mlk_music_openmem(music, musics[i].data, musics[i].datasz) < 0)
-			mlk_panic();
+			mlk_panicf("unable to open music: %s", mlk_err());
 	}
 }
 
--- a/libmlk-rpg/mlk/rpg/map-loader.c	Thu Mar 09 20:30:00 2023 +0100
+++ b/libmlk-rpg/mlk/rpg/map-loader.c	Thu Mar 09 22:33:46 2023 +0100
@@ -218,9 +218,10 @@
 		{ "layer",      parse_layer             },
 	};
 
-	for (size_t i = 0; i < MLK_UTIL_SIZE(props); ++i)
+	for (size_t i = 0; i < MLK_UTIL_SIZE(props); ++i) {
 		if (strncmp(line, props[i].property, strlen(props[i].property)) == 0)
 			return props[i].read(loader, map, line, fp);
+	}
 
 	return 0;
 }
@@ -273,8 +274,6 @@
 	return parse(loader, map, fp);
 }
 
-#if defined(MLK_HAVE_FMEMOPEN)
-
 int
 mlk_map_loader_openmem(struct mlk_map_loader *loader, struct mlk_map *map, const void *data, size_t datasz)
 {
@@ -291,5 +290,3 @@
 
 	return parse(loader, map, fp);
 }
-
-#endif
--- a/libmlk-rpg/mlk/rpg/map-loader.h	Thu Mar 09 20:30:00 2023 +0100
+++ b/libmlk-rpg/mlk/rpg/map-loader.h	Thu Mar 09 22:33:46 2023 +0100
@@ -19,8 +19,6 @@
 #ifndef MLK_RPG_MAP_LOADER_H
 #define MLK_RPG_MAP_LOADER_H
 
-#include <mlk/util/sysconfig.h>
-
 #include <stddef.h>
 
 enum mlk_map_layer_type;
@@ -132,8 +130,6 @@
                     struct mlk_map *map,
                     const char *path);
 
-#if defined(MLK_HAVE_FMEMOPEN)
-
 /**
  * Try to open a map from the given path.
  *
@@ -144,7 +140,6 @@
  * \param data the map content
  * \param datasz the map content length
  * \return 0 on success or -1 on error
- * \note This function is available only if MLK_HAVE_FMEMOPEN is defined.
  */
 int
 mlk_map_loader_openmem(struct mlk_map_loader *loader,
@@ -152,8 +147,6 @@
                        const void *data,
                        size_t datasz);
 
-#endif
-
 #if defined(__cplusplus)
 }
 #endif
--- a/libmlk-rpg/mlk/rpg/tileset-loader.c	Thu Mar 09 20:30:00 2023 +0100
+++ b/libmlk-rpg/mlk/rpg/tileset-loader.c	Thu Mar 09 22:33:46 2023 +0100
@@ -297,8 +297,6 @@
 	return parse(loader, tileset, fp);
 }
 
-#if defined(MLK_HAVE_FMEMOPEN)
-
 int
 mlk_tileset_loader_openmem(struct mlk_tileset_loader *loader,
                            struct mlk_tileset *tileset,
@@ -318,5 +316,3 @@
 
 	return parse(loader, tileset, fp);
 }
-
-#endif
--- a/libmlk-rpg/mlk/rpg/tileset-loader.h	Thu Mar 09 20:30:00 2023 +0100
+++ b/libmlk-rpg/mlk/rpg/tileset-loader.h	Thu Mar 09 22:33:46 2023 +0100
@@ -34,8 +34,6 @@
  * See tileset-file.h for an implementation of this module using files.
  */
 
-#include <mlk/util/sysconfig.h>
-
 #include <stddef.h>
 
 struct mlk_animation;
@@ -147,8 +145,6 @@
                         struct mlk_tileset *tileset,
                         const char *path);
 
-#if defined(MLK_HAVE_FMEMOPEN)
-
 /**
  * Open a tileset from a const binary data.
  *
@@ -163,7 +159,6 @@
  * \param data the tileset content
  * \param datasz the tileset content length
  * \return 0 on success or an error code on failure
- * \note This function is available only if MLK_HAVE_FMEMOPEN is defined.
  */
 int
 mlk_tileset_loader_openmem(struct mlk_tileset_loader *loader,
@@ -171,8 +166,6 @@
                            const void *data,
                            size_t datasz);
 
-#endif
-
 #if defined(__cplusplus)
 }
 #endif
--- a/libmlk-ui/mlk/ui/debug.c	Thu Mar 09 20:30:00 2023 +0100
+++ b/libmlk-ui/mlk/ui/debug.c	Thu Mar 09 22:33:46 2023 +0100
@@ -28,6 +28,8 @@
 struct mlk_debug_options mlk_debug_options = {
 #if !defined(NDEBUG)
 	.enable = 1
+#else
+    .enable = 0
 #endif
 };
 
--- a/libmlk-util/mlk/util/dir.c	Thu Mar 09 20:30:00 2023 +0100
+++ b/libmlk-util/mlk/util/dir.c	Thu Mar 09 22:33:46 2023 +0100
@@ -149,5 +149,5 @@
 void
 mlk_dir_finish(struct mlk_dir_iter *iter)
 {
-	return handle_finish(iter);
+	handle_finish(iter);
 }
--- a/libmlk-util/mlk/util/fmemopen.c	Thu Mar 09 20:30:00 2023 +0100
+++ b/libmlk-util/mlk/util/fmemopen.c	Thu Mar 09 22:33:46 2023 +0100
@@ -49,11 +49,11 @@
 	if (strchr(mode, 'b'))
 		flags |= _O_BINARY;
 
-	if (!GetTempPath(sizeof (temppath), temppath))
+	if (!GetTempPathA(sizeof (temppath), temppath))
 		return NULL;
-	if (!GetTempFileName(temppath, "MLK", 0, filename))
+	if (!GetTempFileNameA(temppath, "MLK", 0, filename))
 		return NULL;
-	if ((fd = _sopen(temppath, flags, _SH_DENYRW, _S_IREAD | _S_IWRITE)) < 0)
+	if (_sopen_s(&fd, filename, flags, _SH_DENYRW, _S_IREAD | _S_IWRITE) < 0)
 		return NULL;
 	if (!(fp = _fdopen(fd, mode))) {
 		_close(fd);
--- a/libmlk-util/mlk/util/openbsd/basename.c	Thu Mar 09 20:30:00 2023 +0100
+++ b/libmlk-util/mlk/util/openbsd/basename.c	Thu Mar 09 22:33:46 2023 +0100
@@ -26,6 +26,8 @@
 #       include <libgen.h>
 #endif
 
+#include <mlk/util/util.h>
+
 #if !defined(MLK_HAVE_BASENAME)
 
 char *
--- a/libmlk-util/mlk/util/openbsd/dirname.c	Thu Mar 09 20:30:00 2023 +0100
+++ b/libmlk-util/mlk/util/openbsd/dirname.c	Thu Mar 09 22:33:46 2023 +0100
@@ -26,6 +26,8 @@
 #       include <libgen.h>
 #endif
 
+#include <mlk/util/util.h>
+
 #if !defined(MLK_HAVE_DIRNAME)
 
 char *
--- a/libmlk-util/mlk/util/util.h	Thu Mar 09 20:30:00 2023 +0100
+++ b/libmlk-util/mlk/util/util.h	Thu Mar 09 22:33:46 2023 +0100
@@ -33,6 +33,12 @@
 extern "C" {
 #endif
 
+#if defined(_MSC_VER)
+#       define MLK_THREAD_LOCAL
+#else
+#       define MLK_THREAD_LOCAL _Thread_local
+#endif
+
 #if defined(MLK_HAVE_PATH_MAX)
 #       define MLK_PATH_MAX PATH_MAX
 #else