[PATCH] Cygwin: Make native clipboard layout same for 32- and 64-bit
Ken Brown
kbrown@cornell.edu
Sat Oct 9 14:19:19 GMT 2021
On 10/8/2021 5:52 AM, Takashi Yano wrote:
> How about simply just:
>
> diff --git a/winsup/cygwin/fhandler_clipboard.cc b/winsup/cygwin/fhandler_clipboard.cc
> index ccdb295f3..d822f4fc4 100644
> --- a/winsup/cygwin/fhandler_clipboard.cc
> +++ b/winsup/cygwin/fhandler_clipboard.cc
> @@ -28,9 +28,10 @@ static const WCHAR *CYGWIN_NATIVE = L"CYGWIN_NATIVE_CLIPBOARD";
>
> typedef struct
> {
> - timestruc_t timestamp;
> - size_t len;
> - char data[1];
> + uint64_t tv_sec;
> + uint64_t tv_nsec;
> + uint64_t len;
> + char data[1];
> } cygcb_t;
The only problem with this is that it might leave readers scratching their heads
unless they look at the commit that introduced this. What about something like
the following, in which the code speaks for itself:
diff --git a/winsup/cygwin/fhandler_clipboard.cc
b/winsup/cygwin/fhandler_clipboard.cc
index ccdb295f3..028c00f1e 100644
--- a/winsup/cygwin/fhandler_clipboard.cc
+++ b/winsup/cygwin/fhandler_clipboard.cc
@@ -26,12 +26,26 @@ details. */
static const WCHAR *CYGWIN_NATIVE = L"CYGWIN_NATIVE_CLIPBOARD";
+#ifdef __x86_64__
typedef struct
{
timestruc_t timestamp;
size_t len;
char data[1];
} cygcb_t;
+#else
+/* Use same layout. */
+typedef struct
+{
+ struct
+ {
+ int64_t tv_sec;
+ int64_t tv_nsec;
+ } timestamp;
+ uint64_t len;
+ char data[1];
+} cygcb_t;
+#endif
fhandler_dev_clipboard::fhandler_dev_clipboard ()
: fhandler_base (), pos (0), membuffer (NULL), msize (0)
@@ -74,7 +88,14 @@ fhandler_dev_clipboard::set_clipboard (const void *buf,
size_t len)
}
clipbuf = (cygcb_t *) GlobalLock (hmem);
+#ifdef __x86_64__
clock_gettime (CLOCK_REALTIME, &clipbuf->timestamp);
+#else
+ timestruc_t ts;
+ clock_gettime (CLOCK_REALTIME, &ts);
+ clipbuf->timestamp->tv_sec = ts.tv_sec;
+ clipbuf->timestamp->tv_nsec = ts.tv_nsec;
+#endif
clipbuf->len = len;
memcpy (clipbuf->data, buf, len);
@@ -179,7 +200,14 @@ fhandler_dev_clipboard::fstat (struct stat *buf)
&& (hglb = GetClipboardData (format))
&& (clipbuf = (cygcb_t *) GlobalLock (hglb)))
{
+#ifdef __x86_64__
buf->st_atim = buf->st_mtim = clipbuf->timestamp;
+#else
+ timestruc_t ts;
+ ts.tv_sec = clipbuf->timestamp->tv_sec;
+ ts.tv_nsec = clipbuf->timestamp->tv_nsec;
+ buf->st_atim = buf->st_mtim = ts;
+#endif
buf->st_size = clipbuf->len;
GlobalUnlock (hglb);
}
Ken
More information about the Cygwin-patches
mailing list