]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Common source file changes not applicable to open-vm-tools.
authorOliver Kurth <okurth@vmware.com>
Wed, 27 Feb 2019 22:39:54 +0000 (14:39 -0800)
committerOliver Kurth <okurth@vmware.com>
Wed, 27 Feb 2019 22:39:54 +0000 (14:39 -0800)
open-vm-tools/services/plugins/dndcp/dnd/dnd.h
open-vm-tools/services/plugins/dndcp/dnd/dndCommon.c

index c64869d54f0f707e67d6113c44bfcb0eed65ff1d..9701f45f640691b441b6b9bd2afef2f5ae005ff4 100644 (file)
@@ -292,6 +292,10 @@ Bool DnD_CPNameListToDynBufArray(char *fileList,
                                  DynBufArray *dynBufArray);
 char *DnD_GetLastDirName(const char *str);
 
+void DnD_SetCPClipboardAndTruncateText(CPClipboard *clip,
+                                       char *destBuf,
+                                       size_t len);
+
 /* vmblock support functions. */
 Bool DnD_InitializeBlocking(DnDBlockControl *blkCtrl);
 Bool DnD_UninitializeBlocking(DnDBlockControl *blkCtrl);
index e8b4e808874be4b010b8f716d58c3a92753d61b2..fc369513e4e156bacd0bdefa943e5626fe7320b5 100644 (file)
 #include <limits.h>
 
 #include "vmware.h"
+#include "codeset.h"
 #include "dndInt.h"
 #include "dnd.h"
+#include "dndClipboard.h"
 #include "file.h"
 #include "str.h"
 #include "random.h"
@@ -671,6 +673,46 @@ DnD_GetLastDirName(const char *str) // IN
    return Unicode_AllocWithLength(str + start, res, STRING_ENCODING_UTF8);
 }
 
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * DnD_SetCPClipboardAndTruncateText --
+ *
+ *    Truncate the text if the size exceeds the maximum size and then put it
+ *    into clip.
+ *
+ * Results:
+ *    None
+ *
+ * Side effects:
+ *    The destBuf should be released by the caller where the destBuf allocated.
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+void
+DnD_SetCPClipboardAndTruncateText(CPClipboard *clip, // IN/OUT
+                                  char *destBuf,     // IN
+                                  size_t len)        // IN
+{
+   size_t bytesLeft = clip->maxSize - CPClipboard_GetTotalSize(clip) - 1;
+
+   // Truncate if the length is greater than max allowed.
+   if (len > bytesLeft) {
+      size_t boundaryPoint =
+         CodeSet_Utf8FindCodePointBoundary(destBuf, bytesLeft - 1);
+      destBuf[boundaryPoint] = '\0';
+      ASSERT(Unicode_IsBufferValid(destBuf, -1, STRING_ENCODING_UTF8));
+      Log("%s: Truncating text from %" FMTSZ "d chars to %" FMTSZ "d chars.\n",
+          __FUNCTION__, len - 1, boundaryPoint);
+      len = boundaryPoint + 1;
+   }
+
+   CPClipboard_SetItem(clip, CPFORMAT_TEXT, destBuf, len);
+   Log("%s: retrieved text (%" FMTSZ "d bytes) from clipboard.\n",
+      __FUNCTION__, len);
+}
+
 
 /* Transport layer big buffer support functions. */