public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [PATCH] Cygwin: Make native clipboard layout same for 32- and 64-bit
@ 2021-10-07  5:22 Mark Geisert
  2021-10-07  5:56 ` Mark Geisert
  2021-10-08  9:52 ` Takashi Yano
  0 siblings, 2 replies; 14+ messages in thread
From: Mark Geisert @ 2021-10-07  5:22 UTC (permalink / raw)
  To: cygwin-patches

This allows correct copy and pasting between the two Cygwin flavors.

What's done is to overlay the differing timespec formats via a union
within the control structure cygcb_t.  Then conversion between the two
formats is done on the 32-bit side only.

The cygutils package has two programs, putclip and getclip, that also
depend on the layout of the cygcb_t.  At present they have duplicate
defs of struct cygcb_t defined here as no Cygwin header provides it.

---
 winsup/cygwin/fhandler_clipboard.cc | 39 +++++++++++++++++++++--------
 1 file changed, 28 insertions(+), 11 deletions(-)

diff --git a/winsup/cygwin/fhandler_clipboard.cc b/winsup/cygwin/fhandler_clipboard.cc
index ccdb295f3..649e57072 100644
--- a/winsup/cygwin/fhandler_clipboard.cc
+++ b/winsup/cygwin/fhandler_clipboard.cc
@@ -28,9 +28,16 @@ static const WCHAR *CYGWIN_NATIVE = L"CYGWIN_NATIVE_CLIPBOARD";
 
 typedef struct
 {
-  timestruc_t	timestamp;
-  size_t	len;
-  char		data[1];
+  union
+  {
+    struct timespec ts; // 8 bytes on 32-bit Cygwin, 16 bytes on 64-bit Cygwin
+    struct
+    {
+      uint64_t	cb_sec;
+      uint64_t	cb_nsec;
+    };
+  };
+  uint64_t	cb_size;
 } cygcb_t;
 
 fhandler_dev_clipboard::fhandler_dev_clipboard ()
@@ -74,9 +81,14 @@ fhandler_dev_clipboard::set_clipboard (const void *buf, size_t len)
 	}
       clipbuf = (cygcb_t *) GlobalLock (hmem);
 
-      clock_gettime (CLOCK_REALTIME, &clipbuf->timestamp);
-      clipbuf->len = len;
-      memcpy (clipbuf->data, buf, len);
+      clock_gettime (CLOCK_REALTIME, &clipbuf->ts);
+#ifndef __x86_64__
+      // expand 32-bit timespec layout to 64-bit layout
+      clipbuf->cb_nsec = clipbuf->ts.tv_nsec;
+      clipbuf->cb_sec = clipbuf->ts.tv_sec;
+#endif
+      clipbuf->cb_size = len;
+      memcpy (&clipbuf[1], buf, len); // append data
 
       GlobalUnlock (hmem);
       EmptyClipboard ();
@@ -179,8 +191,13 @@ fhandler_dev_clipboard::fstat (struct stat *buf)
 	  && (hglb = GetClipboardData (format))
 	  && (clipbuf = (cygcb_t *) GlobalLock (hglb)))
 	{
-	  buf->st_atim = buf->st_mtim = clipbuf->timestamp;
-	  buf->st_size = clipbuf->len;
+#ifndef __x86_64__
+	  // compress 64-bit timespec layout to 32-bit layout
+	  clipbuf->ts.tv_sec = clipbuf->cb_sec;
+	  clipbuf->ts.tv_nsec = clipbuf->cb_nsec;
+#endif
+	  buf->st_atim = buf->st_mtim = clipbuf->ts;
+	  buf->st_size = clipbuf->cb_size;
 	  GlobalUnlock (hglb);
 	}
       CloseClipboard ();
@@ -218,10 +235,10 @@ fhandler_dev_clipboard::read (void *ptr, size_t& len)
     {
       cygcb_t *clipbuf = (cygcb_t *) cb_data;
 
-      if (pos < (off_t) clipbuf->len)
+      if (pos < (off_t) clipbuf->cb_size)
 	{
-	  ret = ((len > (clipbuf->len - pos)) ? (clipbuf->len - pos) : len);
-	  memcpy (ptr, clipbuf->data + pos , ret);
+	  ret = (len > (clipbuf->cb_size - pos)) ? clipbuf->cb_size - pos : len;
+	  memcpy (ptr, &clipbuf[1] + pos , ret);
 	  pos += ret;
 	}
     }
-- 
2.33.0


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2021-10-25  8:28 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-07  5:22 [PATCH] Cygwin: Make native clipboard layout same for 32- and 64-bit Mark Geisert
2021-10-07  5:56 ` Mark Geisert
2021-10-08  9:52 ` Takashi Yano
2021-10-09 14:19   ` Ken Brown
2021-10-09 14:29     ` Jon Turney
2021-10-09 14:43       ` Ken Brown
2021-10-11  6:13         ` Mark Geisert
2021-10-11 12:11           ` Ken Brown
2021-10-22 15:11             ` Corinna Vinschen
2021-10-23  5:35               ` Mark Geisert
2021-10-23 20:32                 ` Ken Brown
2021-10-23 21:53                   ` Mark Geisert
2021-10-23 23:58               ` Takashi Yano
2021-10-25  8:28                 ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).