diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3d4e18fd..f37cf39f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -90,9 +90,7 @@ set_target_properties(glfw PROPERTIES POSITION_INDEPENDENT_CODE ON FOLDER "GLFW3") -target_compile_definitions(glfw PRIVATE - _GLFW_USE_CONFIG_H - $<$:_XOPEN_SOURCE=600>) +target_compile_definitions(glfw PRIVATE _GLFW_USE_CONFIG_H) target_include_directories(glfw PUBLIC "$" "$/include>") diff --git a/src/cocoa_monitor.m b/src/cocoa_monitor.m index 6108342c..bfcf4510 100644 --- a/src/cocoa_monitor.m +++ b/src/cocoa_monitor.m @@ -264,7 +264,7 @@ void _glfwPollMonitorsNS(void) const CGSize size = CGDisplayScreenSize(displays[i]); char* name = getDisplayName(displays[i]); if (!name) - name = strdup("Unknown"); + name = _glfw_strdup("Unknown"); monitor = _glfwAllocMonitor(name, size.width, size.height); monitor->ns.displayID = displays[i]; diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 10d4a0c1..81b1acfd 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -707,7 +707,7 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; NSUInteger i; for (i = 0; i < count; i++) - paths[i] = strdup([[e nextObject] UTF8String]); + paths[i] = _glfw_strdup([[e nextObject] UTF8String]); _glfwInputDrop(window, (int) count, (const char**) paths); @@ -1813,7 +1813,7 @@ const char* _glfwPlatformGetClipboardString(void) } free(_glfw.ns.clipboardString); - _glfw.ns.clipboardString = strdup([object UTF8String]); + _glfw.ns.clipboardString = _glfw_strdup([object UTF8String]); return _glfw.ns.clipboardString; } diff --git a/src/init.c b/src/init.c index c9f0da69..4ed92951 100644 --- a/src/init.c +++ b/src/init.c @@ -138,10 +138,25 @@ static void terminate(void) } +////////////////////////////////////////////////////////////////////////// +////// GLFW internal API ////// +////////////////////////////////////////////////////////////////////////// + +char* _glfw_strdup(const char* source) +{ + const size_t length = strlen(source); + char* result = calloc(length + 1, 1); + strcpy(result, source); + return result; +} + + ////////////////////////////////////////////////////////////////////////// ////// GLFW event API ////// ////////////////////////////////////////////////////////////////////////// +// Notifies shared code of an error +// void _glfwInputError(int code, const char* format, ...) { _GLFWerror* error; diff --git a/src/input.c b/src/input.c index 408c8be6..d70b4a60 100644 --- a/src/input.c +++ b/src/input.c @@ -398,7 +398,7 @@ _GLFWjoystick* _glfwAllocJoystick(const char* name, js = _glfw.joysticks + jid; js->present = GLFW_TRUE; - js->name = strdup(name); + js->name = _glfw_strdup(name); js->axes = calloc(axisCount, sizeof(float)); js->buttons = calloc(buttonCount + hatCount * 4, 1); js->hats = calloc(hatCount, 1); diff --git a/src/internal.h b/src/internal.h index eea5a35f..cca19783 100644 --- a/src/internal.h +++ b/src/internal.h @@ -745,3 +745,5 @@ GLFWbool _glfwInitVulkan(int mode); void _glfwTerminateVulkan(void); const char* _glfwGetVulkanResultString(VkResult result); +char* _glfw_strdup(const char* source); + diff --git a/src/monitor.c b/src/monitor.c index cca77f5f..050a046c 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -165,7 +165,7 @@ _GLFWmonitor* _glfwAllocMonitor(const char* name, int widthMM, int heightMM) monitor->heightMM = heightMM; if (name) - monitor->name = strdup(name); + monitor->name = _glfw_strdup(name); return monitor; } diff --git a/src/win32_platform.h b/src/win32_platform.h index 958a3137..72718ada 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -67,11 +67,6 @@ #include #include -#if defined(_MSC_VER) - #include - #define strdup _strdup -#endif - // HACK: Define macros that some windows.h variants don't #ifndef WM_MOUSEHWHEEL #define WM_MOUSEHWHEEL 0x020E diff --git a/src/wl_monitor.c b/src/wl_monitor.c index 10ef0e12..ed351e76 100644 --- a/src/wl_monitor.c +++ b/src/wl_monitor.c @@ -52,7 +52,7 @@ static void geometry(void* data, monitor->heightMM = physicalHeight; snprintf(name, sizeof(name), "%s %s", make, model); - monitor->name = strdup(name); + monitor->name = _glfw_strdup(name); } static void mode(void* data, diff --git a/src/wl_window.c b/src/wl_window.c index 57e6f2ad..476b1b0c 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -437,7 +437,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, } if (wndconfig->title) - window->wl.title = strdup(wndconfig->title); + window->wl.title = _glfw_strdup(wndconfig->title); if (wndconfig->visible) { @@ -497,7 +497,7 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title) { if (window->wl.title) free(window->wl.title); - window->wl.title = strdup(title); + window->wl.title = _glfw_strdup(title); if (window->wl.shellSurface) wl_shell_surface_set_title(window->wl.shellSurface, title); } diff --git a/src/x11_window.c b/src/x11_window.c index 1520b825..02c49cb1 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -1056,7 +1056,7 @@ static const char* getSelectionString(Atom selection) if (targets[i] == XA_STRING) *selectionString = convertLatin1toUTF8(data); else - *selectionString = strdup(data); + *selectionString = _glfw_strdup(data); } XFree(data); @@ -2834,7 +2834,7 @@ void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor) void _glfwPlatformSetClipboardString(const char* string) { free(_glfw.x11.clipboardString); - _glfw.x11.clipboardString = strdup(string); + _glfw.x11.clipboardString = _glfw_strdup(string); XSetSelectionOwner(_glfw.x11.display, _glfw.x11.CLIPBOARD, @@ -3026,7 +3026,7 @@ GLFWAPI void glfwSetX11SelectionString(const char* string) _GLFW_REQUIRE_INIT(); free(_glfw.x11.primarySelectionString); - _glfw.x11.primarySelectionString = strdup(string); + _glfw.x11.primarySelectionString = _glfw_strdup(string); XSetSelectionOwner(_glfw.x11.display, _glfw.x11.PRIMARY,