Skip to content

Commit

Permalink
remove more stl
Browse files Browse the repository at this point in the history
  • Loading branch information
ColleagueRiley committed Jan 6, 2025
1 parent 6579e56 commit 0076937
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 19 additions & 7 deletions RGFW.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,17 @@ int main() {
#ifndef RGFW_MEMCPY
#include <string.h>

#ifdef RGFW_WINDOWS
#include <wchar.h>
#include <locale.h>
#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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -5293,8 +5300,6 @@ char* RGFW_readClipboard(size_t* size) {
#include <windows.h>

#include <processthreadsapi.h>
#include <wchar.h>
#include <locale.h>
#include <windowsx.h>
#include <shellapi.h>
#include <shellscalingapi.h>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand All @@ -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 */
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions examples/nostl/nostl.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,6 @@ int __main(void) {
}

RGFW_window_close(win);

return 0;
}

0 comments on commit 0076937

Please sign in to comment.