From 4d68daedc91b04a1185b2a8c431e9446a24075cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Thu, 24 Mar 2022 20:34:04 +0100 Subject: [PATCH] Wayland: Clean up clipboard writing (cherry picked from commit 34418951ccc3eeb3380cd3c93b5d4cf357151cbe) --- src/wl_window.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/wl_window.c b/src/wl_window.c index 690e69e2..3ac00fbd 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -1725,10 +1725,6 @@ static void dataSourceHandleSend(void* userData, const char* mimeType, int fd) { - char* string = _glfw.wl.clipboardString; - size_t len = strlen(string); - int ret; - if (_glfw.wl.selectionSource != source) { _glfwInputError(GLFW_PLATFORM_ERROR, @@ -1737,6 +1733,7 @@ static void dataSourceHandleSend(void* userData, return; } + char* string = _glfw.wl.clipboardString; if (!string) { _glfwInputError(GLFW_PLATFORM_ERROR, @@ -1753,22 +1750,26 @@ static void dataSourceHandleSend(void* userData, return; } - while (len > 0) + size_t length = strlen(string); + + while (length > 0) { - ret = write(fd, string, len); - if (ret == -1 && errno == EINTR) - continue; - if (ret == -1) + const ssize_t result = write(fd, string, length); + if (result == -1) { + if (errno == EINTR) + continue; + _glfwInputError(GLFW_PLATFORM_ERROR, "Wayland: Error while writing the clipboard: %s", strerror(errno)); - close(fd); - return; + break; } - len -= ret; - string += ret; + + length -= result; + string += result; } + close(fd); }