2000-10-17 09:46:26 +08:00
|
|
|
/* fhandler_dev_clipboard: code to access /dev/clipboard
|
|
|
|
|
2013-01-21 12:34:52 +08:00
|
|
|
Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009, 2011, 2012, 2013
|
|
|
|
Red Hat, Inc
|
2000-10-17 09:46:26 +08:00
|
|
|
|
|
|
|
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"
|
2008-02-01 04:26:01 +08:00
|
|
|
#include <wchar.h>
|
2000-10-17 09:46:26 +08:00
|
|
|
#include <wingdi.h>
|
|
|
|
#include <winuser.h>
|
2001-07-27 03:22:24 +08:00
|
|
|
#include "cygerrno.h"
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
#include "path.h"
|
2001-07-27 03:22:24 +08:00
|
|
|
#include "fhandler.h"
|
2011-11-14 09:29:49 +08:00
|
|
|
#include "sync.h"
|
|
|
|
#include "dtable.h"
|
|
|
|
#include "cygheap.h"
|
|
|
|
#include "child_info.h"
|
2000-10-17 09:46:26 +08:00
|
|
|
|
2001-03-23 06:11:34 +08:00
|
|
|
/*
|
|
|
|
* Robert Collins:
|
|
|
|
* FIXME: should we use GetClipboardSequenceNumber to tell if the clipboard has
|
|
|
|
* changed? How does /dev/clipboard operate under (say) linux?
|
|
|
|
*/
|
2000-10-17 09:46:26 +08:00
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
static const WCHAR *CYGWIN_NATIVE = L"CYGWIN_NATIVE_CLIPBOARD";
|
2001-03-23 06:11:34 +08:00
|
|
|
/* this is MT safe because windows format id's are atomic */
|
2013-01-21 12:34:52 +08:00
|
|
|
static UINT cygnativeformat;
|
2001-03-23 06:11:34 +08:00
|
|
|
|
2012-03-26 19:24:51 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
timestruc_t timestamp;
|
|
|
|
size_t len;
|
|
|
|
char data[1];
|
|
|
|
} cygcb_t;
|
|
|
|
|
2001-10-23 02:39:22 +08:00
|
|
|
fhandler_dev_clipboard::fhandler_dev_clipboard ()
|
2012-07-03 04:17:27 +08:00
|
|
|
: fhandler_base (), pos (0), membuffer (NULL), msize (0)
|
2000-10-17 09:46:26 +08:00
|
|
|
{
|
2001-03-23 06:11:34 +08:00
|
|
|
/* FIXME: check for errors and loop until we can open the clipboard */
|
|
|
|
OpenClipboard (NULL);
|
2011-05-01 22:35:12 +08:00
|
|
|
cygnativeformat = RegisterClipboardFormatW (CYGWIN_NATIVE);
|
2001-03-23 06:11:34 +08:00
|
|
|
CloseClipboard ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Special clipboard dup to duplicate input and output
|
|
|
|
* handles.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
2013-10-26 00:16:50 +08:00
|
|
|
fhandler_dev_clipboard::dup (fhandler_base * child, int flags)
|
2001-03-23 06:11:34 +08:00
|
|
|
{
|
|
|
|
fhandler_dev_clipboard *fhc = (fhandler_dev_clipboard *) child;
|
2013-10-26 00:16:50 +08:00
|
|
|
fhc->pos = fhc->msize = 0;
|
|
|
|
fhc->membuffer = NULL;
|
|
|
|
return fhandler_base::dup (child, flags);
|
2000-10-17 09:46:26 +08:00
|
|
|
}
|
|
|
|
|
2001-03-23 06:11:34 +08:00
|
|
|
static int
|
|
|
|
set_clipboard (const void *buf, size_t len)
|
|
|
|
{
|
|
|
|
HGLOBAL hmem;
|
|
|
|
/* Native CYGWIN format */
|
2009-06-05 01:14:53 +08:00
|
|
|
if (OpenClipboard (NULL))
|
2001-03-23 06:11:34 +08:00
|
|
|
{
|
2012-03-26 19:24:51 +08:00
|
|
|
cygcb_t *clipbuf;
|
|
|
|
|
|
|
|
hmem = GlobalAlloc (GMEM_MOVEABLE, sizeof (cygcb_t) + len);
|
2009-06-05 01:14:53 +08:00
|
|
|
if (!hmem)
|
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
CloseClipboard ();
|
|
|
|
return -1;
|
|
|
|
}
|
2012-03-26 19:24:51 +08:00
|
|
|
clipbuf = (cygcb_t *) GlobalLock (hmem);
|
|
|
|
|
|
|
|
clock_gettime (CLOCK_REALTIME, &clipbuf->timestamp);
|
|
|
|
clipbuf->len = len;
|
|
|
|
memcpy (clipbuf->data, buf, len);
|
|
|
|
|
2009-06-05 01:14:53 +08:00
|
|
|
GlobalUnlock (hmem);
|
|
|
|
EmptyClipboard ();
|
|
|
|
HANDLE ret = SetClipboardData (cygnativeformat, hmem);
|
|
|
|
CloseClipboard ();
|
|
|
|
/* According to MSDN, hmem must not be free'd after transferring the
|
2011-06-06 13:02:13 +08:00
|
|
|
data to the clipboard via SetClipboardData. */
|
2009-06-05 01:14:53 +08:00
|
|
|
/* GlobalFree (hmem); */
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
return -1;
|
|
|
|
}
|
2001-03-23 06:11:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* CF_TEXT/CF_OEMTEXT for copying to wordpad and the like */
|
2008-02-26 02:32:23 +08:00
|
|
|
len = sys_mbstowcs (NULL, 0, (const char *) buf, len);
|
2008-02-01 04:26:01 +08:00
|
|
|
if (!len)
|
|
|
|
{
|
2009-06-05 01:14:53 +08:00
|
|
|
set_errno (EILSEQ);
|
2008-02-01 04:26:01 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2009-06-05 01:14:53 +08:00
|
|
|
if (OpenClipboard (NULL))
|
2001-03-23 06:11:34 +08:00
|
|
|
{
|
2012-03-26 19:24:51 +08:00
|
|
|
PWCHAR clipbuf;
|
|
|
|
|
2009-06-05 01:14:53 +08:00
|
|
|
hmem = GlobalAlloc (GMEM_MOVEABLE, (len + 1) * sizeof (WCHAR));
|
|
|
|
if (!hmem)
|
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
CloseClipboard ();
|
|
|
|
return -1;
|
|
|
|
}
|
2012-03-26 19:24:51 +08:00
|
|
|
clipbuf = (PWCHAR) GlobalLock (hmem);
|
|
|
|
sys_mbstowcs (clipbuf, len + 1, (const char *) buf);
|
2009-06-05 01:14:53 +08:00
|
|
|
GlobalUnlock (hmem);
|
|
|
|
HANDLE ret = SetClipboardData (CF_UNICODETEXT, hmem);
|
|
|
|
CloseClipboard ();
|
|
|
|
/* According to MSDN, hmem must not be free'd after transferring the
|
2011-06-06 13:02:13 +08:00
|
|
|
data to the clipboard via SetClipboardData. */
|
2009-06-05 01:14:53 +08:00
|
|
|
/* GlobalFree (hmem); */
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
return -1;
|
|
|
|
}
|
2001-03-23 06:11:34 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: arbitrary seeking is not handled */
|
2009-07-25 04:54:33 +08:00
|
|
|
ssize_t __stdcall
|
2001-03-23 06:11:34 +08:00
|
|
|
fhandler_dev_clipboard::write (const void *buf, size_t len)
|
2000-10-17 09:46:26 +08:00
|
|
|
{
|
2012-07-03 04:17:27 +08:00
|
|
|
/* write to our membuffer */
|
|
|
|
size_t cursize = msize;
|
|
|
|
void *tempbuffer = realloc (membuffer, cursize + len);
|
|
|
|
if (!tempbuffer)
|
2001-03-23 06:11:34 +08:00
|
|
|
{
|
2012-07-03 04:17:27 +08:00
|
|
|
debug_printf ("Couldn't realloc() clipboard buffer for write");
|
|
|
|
return -1;
|
2001-03-23 06:11:34 +08:00
|
|
|
}
|
2012-07-03 04:17:27 +08:00
|
|
|
membuffer = tempbuffer;
|
|
|
|
msize = cursize + len;
|
|
|
|
memcpy ((unsigned char *) membuffer + cursize, buf, len);
|
|
|
|
|
|
|
|
/* now pass to windows */
|
|
|
|
if (set_clipboard (membuffer, msize))
|
2001-03-23 06:11:34 +08:00
|
|
|
{
|
2012-07-03 04:17:27 +08:00
|
|
|
/* FIXME: membuffer is now out of sync with pos, but msize
|
|
|
|
is used above */
|
|
|
|
return -1;
|
2001-03-23 06:11:34 +08:00
|
|
|
}
|
2012-07-03 04:17:27 +08:00
|
|
|
|
|
|
|
pos = msize;
|
|
|
|
return len;
|
2000-10-17 09:46:26 +08:00
|
|
|
}
|
|
|
|
|
2013-01-21 12:34:52 +08:00
|
|
|
int __reg2
|
2013-04-23 17:44:36 +08:00
|
|
|
fhandler_dev_clipboard::fstat (struct stat *buf)
|
2012-03-26 19:24:51 +08:00
|
|
|
{
|
|
|
|
buf->st_mode = S_IFCHR | STD_RBITS | STD_WBITS | S_IWGRP | S_IWOTH;
|
|
|
|
buf->st_uid = geteuid32 ();
|
|
|
|
buf->st_gid = getegid32 ();
|
|
|
|
buf->st_nlink = 1;
|
|
|
|
buf->st_blksize = PREFERRED_IO_BLKSIZE;
|
|
|
|
|
|
|
|
buf->st_ctim.tv_sec = 1164931200L; /* Arbitrary value: 2006-12-01 */
|
|
|
|
buf->st_ctim.tv_nsec = 0L;
|
|
|
|
buf->st_birthtim = buf->st_atim = buf->st_mtim = buf->st_ctim;
|
|
|
|
|
|
|
|
if (OpenClipboard (NULL))
|
|
|
|
{
|
|
|
|
UINT formatlist[1] = { cygnativeformat };
|
|
|
|
int format;
|
|
|
|
HGLOBAL hglb;
|
|
|
|
cygcb_t *clipbuf;
|
|
|
|
|
|
|
|
if ((format = GetPriorityClipboardFormat (formatlist, 1)) > 0
|
|
|
|
&& (hglb = GetClipboardData (format))
|
|
|
|
&& (clipbuf = (cygcb_t *) GlobalLock (hglb)))
|
|
|
|
{
|
|
|
|
buf->st_atim = buf->st_mtim = clipbuf->timestamp;
|
|
|
|
buf->st_size = clipbuf->len;
|
|
|
|
GlobalUnlock (hglb);
|
|
|
|
}
|
|
|
|
CloseClipboard ();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-21 12:34:52 +08:00
|
|
|
void __reg3
|
2002-12-14 12:01:32 +08:00
|
|
|
fhandler_dev_clipboard::read (void *ptr, size_t& len)
|
2000-10-17 09:46:26 +08:00
|
|
|
{
|
|
|
|
HGLOBAL hglb;
|
2012-07-03 04:17:27 +08:00
|
|
|
size_t ret = 0;
|
2001-03-23 06:11:34 +08:00
|
|
|
UINT formatlist[2];
|
2013-01-21 12:34:52 +08:00
|
|
|
UINT format;
|
2012-07-03 04:17:27 +08:00
|
|
|
LPVOID cb_data;
|
2012-08-17 17:23:34 +08:00
|
|
|
int rach;
|
2009-06-05 01:14:53 +08:00
|
|
|
|
|
|
|
if (!OpenClipboard (NULL))
|
|
|
|
{
|
2012-07-03 04:17:27 +08:00
|
|
|
len = 0;
|
2009-06-05 01:14:53 +08:00
|
|
|
return;
|
|
|
|
}
|
2012-07-03 04:17:27 +08:00
|
|
|
formatlist[0] = cygnativeformat;
|
|
|
|
formatlist[1] = CF_UNICODETEXT;
|
|
|
|
if ((format = GetPriorityClipboardFormat (formatlist, 2)) <= 0
|
|
|
|
|| !(hglb = GetClipboardData (format))
|
|
|
|
|| !(cb_data = GlobalLock (hglb)))
|
2000-10-17 09:46:26 +08:00
|
|
|
{
|
2009-06-05 01:14:53 +08:00
|
|
|
CloseClipboard ();
|
2012-07-03 04:17:27 +08:00
|
|
|
len = 0;
|
2009-06-05 01:14:53 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (format == cygnativeformat)
|
|
|
|
{
|
2012-07-03 04:17:27 +08:00
|
|
|
cygcb_t *clipbuf = (cygcb_t *) cb_data;
|
2009-07-01 05:18:44 +08:00
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
if (pos < (off_t) clipbuf->len)
|
2012-08-17 17:23:34 +08:00
|
|
|
{
|
2012-07-03 04:17:27 +08:00
|
|
|
ret = ((len > (clipbuf->len - pos)) ? (clipbuf->len - pos) : len);
|
|
|
|
memcpy (ptr, clipbuf->data + pos , ret);
|
|
|
|
pos += ret;
|
2002-12-14 12:01:32 +08:00
|
|
|
}
|
2009-06-05 01:14:53 +08:00
|
|
|
}
|
2012-08-17 17:23:34 +08:00
|
|
|
else if ((rach = get_readahead ()) >= 0)
|
|
|
|
{
|
|
|
|
/* Deliver from read-ahead buffer. */
|
|
|
|
char * out_ptr = (char *) ptr;
|
|
|
|
* out_ptr++ = rach;
|
|
|
|
ret = 1;
|
|
|
|
while (ret < len && (rach = get_readahead ()) >= 0)
|
|
|
|
{
|
|
|
|
* out_ptr++ = rach;
|
|
|
|
ret++;
|
|
|
|
}
|
|
|
|
}
|
2009-06-05 01:14:53 +08:00
|
|
|
else
|
|
|
|
{
|
2012-07-03 04:17:27 +08:00
|
|
|
wchar_t *buf = (wchar_t *) cb_data;
|
2008-02-16 01:53:11 +08:00
|
|
|
|
2012-07-03 04:17:27 +08:00
|
|
|
size_t glen = GlobalSize (hglb) / sizeof (WCHAR) - 1;
|
2013-04-23 17:44:36 +08:00
|
|
|
if (pos < (off_t) glen)
|
2009-06-05 01:14:53 +08:00
|
|
|
{
|
2013-01-21 12:34:52 +08:00
|
|
|
/* If caller's buffer is too small to hold at least one
|
|
|
|
max-size character, redirect algorithm to local
|
|
|
|
read-ahead buffer, finally fill class read-ahead buffer
|
2012-08-17 17:23:34 +08:00
|
|
|
with result and feed caller from there. */
|
|
|
|
char *conv_ptr = (char *) ptr;
|
|
|
|
size_t conv_len = len;
|
|
|
|
#define cprabuf_len MB_LEN_MAX /* max MB_CUR_MAX of all encodings */
|
|
|
|
char cprabuf [cprabuf_len];
|
|
|
|
if (len < cprabuf_len)
|
|
|
|
{
|
|
|
|
conv_ptr = cprabuf;
|
|
|
|
conv_len = cprabuf_len;
|
|
|
|
}
|
|
|
|
|
2012-07-03 04:17:27 +08:00
|
|
|
/* Comparing apples and oranges here, but the below loop could become
|
|
|
|
extremly slow otherwise. We rather return a few bytes less than
|
|
|
|
possible instead of being even more slow than usual... */
|
2012-08-17 17:23:34 +08:00
|
|
|
if (glen > pos + conv_len)
|
|
|
|
glen = pos + conv_len;
|
2012-07-03 04:17:27 +08:00
|
|
|
/* This loop is necessary because the number of bytes returned by
|
|
|
|
sys_wcstombs does not indicate the number of wide chars used for
|
|
|
|
it, so we could potentially drop wide chars. */
|
|
|
|
while ((ret = sys_wcstombs (NULL, 0, buf + pos, glen - pos))
|
|
|
|
!= (size_t) -1
|
2013-01-21 12:34:52 +08:00
|
|
|
&& (ret > conv_len
|
2012-08-17 17:23:34 +08:00
|
|
|
/* Skip separated high surrogate: */
|
2013-06-17 18:11:54 +08:00
|
|
|
|| ((buf [glen - 1] & 0xFC00) == 0xD800
|
|
|
|
&& glen - pos > 1)))
|
2012-07-03 04:17:27 +08:00
|
|
|
--glen;
|
|
|
|
if (ret == (size_t) -1)
|
|
|
|
ret = 0;
|
|
|
|
else
|
|
|
|
{
|
2012-08-17 17:23:34 +08:00
|
|
|
ret = sys_wcstombs ((char *) conv_ptr, (size_t) -1,
|
2012-07-03 04:17:27 +08:00
|
|
|
buf + pos, glen - pos);
|
|
|
|
pos = glen;
|
2012-08-17 17:23:34 +08:00
|
|
|
/* If using read-ahead buffer, copy to class read-ahead buffer
|
|
|
|
and deliver first byte. */
|
|
|
|
if (conv_ptr == cprabuf)
|
|
|
|
{
|
|
|
|
puts_readahead (cprabuf, ret);
|
|
|
|
char *out_ptr = (char *) ptr;
|
|
|
|
ret = 0;
|
|
|
|
while (ret < len && (rach = get_readahead ()) >= 0)
|
|
|
|
{
|
|
|
|
* out_ptr++ = rach;
|
|
|
|
ret++;
|
|
|
|
}
|
|
|
|
}
|
2012-07-03 04:17:27 +08:00
|
|
|
}
|
2001-03-23 06:11:34 +08:00
|
|
|
}
|
2000-10-17 09:46:26 +08:00
|
|
|
}
|
2009-06-05 01:14:53 +08:00
|
|
|
GlobalUnlock (hglb);
|
|
|
|
CloseClipboard ();
|
|
|
|
len = ret;
|
2000-10-17 09:46:26 +08:00
|
|
|
}
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
off_t
|
|
|
|
fhandler_dev_clipboard::lseek (off_t offset, int whence)
|
2000-10-17 09:46:26 +08:00
|
|
|
{
|
2001-03-23 06:11:34 +08:00
|
|
|
/* On reads we check this at read time, not seek time.
|
|
|
|
* On writes we use this to decide how to write - empty and write, or open, copy, empty
|
|
|
|
* and write
|
|
|
|
*/
|
|
|
|
pos = offset;
|
|
|
|
/* treat seek like rewind */
|
|
|
|
if (membuffer)
|
2013-10-25 23:04:24 +08:00
|
|
|
{
|
|
|
|
free (membuffer);
|
|
|
|
membuffer = NULL;
|
|
|
|
}
|
2001-03-23 06:11:34 +08:00
|
|
|
msize = 0;
|
2000-10-17 09:46:26 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2005-07-05 11:16:46 +08:00
|
|
|
fhandler_dev_clipboard::close ()
|
2000-10-17 09:46:26 +08:00
|
|
|
{
|
2011-11-14 09:29:49 +08:00
|
|
|
if (!have_execed)
|
2005-07-05 11:16:46 +08:00
|
|
|
{
|
2013-10-26 00:16:50 +08:00
|
|
|
pos = msize = 0;
|
2005-07-05 11:16:46 +08:00
|
|
|
if (membuffer)
|
2005-07-27 22:33:09 +08:00
|
|
|
{
|
|
|
|
free (membuffer);
|
|
|
|
membuffer = NULL;
|
|
|
|
}
|
2005-07-05 11:16:46 +08:00
|
|
|
}
|
2013-10-26 00:16:50 +08:00
|
|
|
return fhandler_base::close ();
|
2000-10-17 09:46:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-07-05 11:16:46 +08:00
|
|
|
fhandler_dev_clipboard::fixup_after_exec ()
|
2000-10-17 09:46:26 +08:00
|
|
|
{
|
2005-11-14 12:28:45 +08:00
|
|
|
if (!close_on_exec ())
|
|
|
|
{
|
|
|
|
pos = msize = 0;
|
|
|
|
membuffer = NULL;
|
|
|
|
}
|
2000-10-17 09:46:26 +08:00
|
|
|
}
|