1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-26 20:28:49 -05:00

Remove use of non-standard function strdup

Related to #873.
This commit is contained in:
Camilla Löwy 2018-01-17 11:56:35 +01:00
parent bb3ab87a18
commit 973bf29622
11 changed files with 29 additions and 19 deletions

View File

@ -90,9 +90,7 @@ set_target_properties(glfw PROPERTIES
POSITION_INDEPENDENT_CODE ON
FOLDER "GLFW3")
target_compile_definitions(glfw PRIVATE
_GLFW_USE_CONFIG_H
$<$<BOOL:${UNIX}>:_XOPEN_SOURCE=600>)
target_compile_definitions(glfw PRIVATE _GLFW_USE_CONFIG_H)
target_include_directories(glfw PUBLIC
"$<BUILD_INTERFACE:${GLFW_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>")

View File

@ -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];

View File

@ -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;
}

View File

@ -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;

View File

@ -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);

View File

@ -745,3 +745,5 @@ GLFWbool _glfwInitVulkan(int mode);
void _glfwTerminateVulkan(void);
const char* _glfwGetVulkanResultString(VkResult result);
char* _glfw_strdup(const char* source);

View File

@ -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;
}

View File

@ -67,11 +67,6 @@
#include <xinput.h>
#include <dbt.h>
#if defined(_MSC_VER)
#include <malloc.h>
#define strdup _strdup
#endif
// HACK: Define macros that some windows.h variants don't
#ifndef WM_MOUSEHWHEEL
#define WM_MOUSEHWHEEL 0x020E

View File

@ -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,

View File

@ -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);
}

View File

@ -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,