From 00769371262c9814db6b50241296e5c46293eb6b Mon Sep 17 00:00:00 2001 From: ColleagueRiley Date: Sun, 5 Jan 2025 21:20:00 -0500 Subject: [PATCH] remove more stl --- Makefile | 2 +- RGFW.h | 26 +++++++++++++++++++------- examples/nostl/nostl.c | 2 ++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 908990f4..0722a907 100644 --- a/Makefile +++ b/Makefile @@ -188,7 +188,7 @@ ifeq ($(CC),emcc) else ifeq ($(detected_OS),Linux) $(CC) $(CFLAGS) -fno-stack-protector -lX11 -lXcursor -lGL -lXi -lXrandr -I. $< -o $@$(EXT) else ifeq ($(detected_OS),windows) - $(CC) $(CFLAGS) $(WARNINGS) -nostdlib -I. $< -lgdi32 -o $@$(EXT) + $(CC) $(CFLAGS) $(WARNINGS) -I. $< -lkernel32 -lgdi32 -lshell32 -lUser32 -nostdlib -o $@$(EXT) else ifeq ($(detected_OS),Darwin) $(CC) $(CFLAGS) $(WARNINGS) -nostdlib -I. $< -framework Foundation -framework AppKit -o $@$(EXT) else diff --git a/RGFW.h b/RGFW.h index 92ccece1..a86aa663 100644 --- a/RGFW.h +++ b/RGFW.h @@ -196,10 +196,17 @@ int main() { #ifndef RGFW_MEMCPY #include + #ifdef RGFW_WINDOWS + #include + #include + #endif + #define RGFW_MEMCPY(dist, src, len) memcpy(dist, src, len) #define RGFW_STRNCMP(s1, s2, max) strncmp(s1, s2, max) //required for X11 #define RGFW_STRTOL(str, endptr, base) strtol(str, endptr, base) +#else +#undef _INC_STRING #endif #if !_MSC_VER @@ -1653,7 +1660,7 @@ RGFW_window* RGFW_window_basic_init(RGFW_rect rect, RGFW_windowArgs args) { u32 i; for (i = 0; i < RGFW_MAX_DROPS; i++) { win->event.droppedFiles[i] = (char*) RGFW_alloc(RGFW_MAX_PATH); - memset(win->event.droppedFiles[i], 0, RGFW_MAX_PATH); + win->event.droppedFiles[i][0] = 0; } #endif @@ -5293,8 +5300,6 @@ char* RGFW_readClipboard(size_t* size) { #include #include -#include -#include #include #include #include @@ -6090,7 +6095,7 @@ RGFW_Event* RGFW_window_checkEvent(RGFW_window* win) { for (i = 0; i < win->event.droppedFilesCount; i++) { const UINT length = DragQueryFileW(drop, i, NULL, 0); WCHAR* buffer = (WCHAR*) RGFW_alloc((size_t) length + 1); - memset(buffer, 0, length + 1); + buffer[length] = 0; DragQueryFileW(drop, i, buffer, length + 1); RGFW_MEMCPY(win->event.droppedFiles[i], createUTF8FromWideStringWin32(buffer), RGFW_MAX_PATH); @@ -6831,10 +6836,13 @@ char* RGFW_readClipboard(size_t* size) { wchar_t* wstr = (wchar_t*) GlobalLock(hData); + char text_null = '\0'; char* text; { + #ifdef LC_ALL setlocale(LC_ALL, "en_US.UTF-8"); + size_t textLen = wcstombs(NULL, wstr, 0); if (textLen == 0) @@ -6846,8 +6854,12 @@ char* RGFW_readClipboard(size_t* size) { if (size != NULL) *size = textLen + 1; - text[textLen] = '\0'; + #else + text = &text_null; + RGFW_UNUSED(wstr); + RGFW_UNUSED(size); + #endif } /* Release the clipboard data */ @@ -6970,8 +6982,8 @@ char* createUTF8FromWideStringWin32(const WCHAR* source) { return NULL; } - target = (char*) RGFW_alloc(size); - memset(target, 0, size); + target = (char*) RGFW_alloc(size + 1); + target[size] = 0; if (!WideCharToMultiByte(CP_UTF8, 0, source, -1, target, size, NULL, NULL)) { RGFW_free(target); diff --git a/examples/nostl/nostl.c b/examples/nostl/nostl.c index 203a9e2f..9ec34612 100644 --- a/examples/nostl/nostl.c +++ b/examples/nostl/nostl.c @@ -72,4 +72,6 @@ int __main(void) { } RGFW_window_close(win); + + return 0; } \ No newline at end of file