From e6f5c9d57d2c36296d8eed223c92a3084ccf4a93 Mon Sep 17 00:00:00 2001 From: DJ Delorie Date: Tue, 17 Oct 2000 01:46:26 +0000 Subject: * fhandler_clipboard.cc: new file * Makefile.in: include fhandler_clipboard.o in DLL_OFILES list. * fhandler.h: add FH_CLIPBOARD to the devices enum. (fhandler_dev_clipboard): new * path.cc (windows_device_names): add "\\dev\\clipboard" (get_device_number): check for "clipboard" * dcrt0.cc: declare a few more functions from winuser.h * dtable.cc (dtable::build_fhandler): check for FH_CLIPBOARD in switch(). --- winsup/cygwin/fhandler_clipboard.cc | 95 +++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 winsup/cygwin/fhandler_clipboard.cc (limited to 'winsup/cygwin/fhandler_clipboard.cc') diff --git a/winsup/cygwin/fhandler_clipboard.cc b/winsup/cygwin/fhandler_clipboard.cc new file mode 100644 index 000000000..6be0b1200 --- /dev/null +++ b/winsup/cygwin/fhandler_clipboard.cc @@ -0,0 +1,95 @@ +/* fhandler_dev_clipboard: code to access /dev/clipboard + + Copyright 2000 Red Hat, Inc + + Written by Charles Wilson (cwilson@ece.gatech.edu) + +This file is part of Cygwin. + +This software is a copyrighted work licensed under the terms of the +Cygwin license. Please consult the file "CYGWIN_LICENSE" for +details. */ + +#include "winsup.h" +#include +#include +#include "cygerrno.h" +#include "fhandler.h" +#include +#include +#include + +static BOOL clipboard_eof; // NOT THREAD-SAFE + +fhandler_dev_clipboard::fhandler_dev_clipboard (const char *name) + : fhandler_base (FH_CLIPBOARD, name) +{ + set_cb (sizeof *this); + clipboard_eof = false; +} + +int +fhandler_dev_clipboard::open (const char *, int flags, mode_t) +{ + set_flags (flags); + clipboard_eof = false; + return 1; +} + +int +fhandler_dev_clipboard::write (const void *, size_t len) +{ + return len; +} + +int +fhandler_dev_clipboard::read (void *ptr, size_t len) +{ + HGLOBAL hglb; + LPSTR lpstr; + int ret; + + if (!clipboard_eof) + { + OpenClipboard(0); + hglb = GetClipboardData(CF_TEXT); + lpstr = (LPSTR) GlobalLock(hglb); + if (len < sizeof (lpstr)) + { + set_errno (EINVAL); + GlobalUnlock (hglb); + CloseClipboard (); + return -1; + } + + ret = snprintf((char *) ptr, len, "%s", lpstr); + GlobalUnlock(hglb); + CloseClipboard(); + set_errno (0); + clipboard_eof = true; + return ret; + } + else + { + return 0; + } +} + +off_t +fhandler_dev_clipboard::lseek (off_t offset, int whence) +{ + return 0; +} + +int +fhandler_dev_clipboard::close (void) +{ + clipboard_eof = false; + return 0; +} + +void +fhandler_dev_clipboard::dump () +{ + paranoid_printf("here, fhandler_dev_clipboard"); +} -- cgit v1.2.3