2000-02-17 20:38:33 +01:00
|
|
|
/* termios.cc: termios for WIN32.
|
|
|
|
|
2013-01-21 05:38:31 +01:00
|
|
|
Copyright 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
|
|
|
|
2008, 2009, 2010, 2011, 2012 Red Hat, Inc.
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
Written by Doug Evans and Steve Chamberlain of Cygnus Support
|
|
|
|
dje@cygnus.com, sac@cygnus.com
|
|
|
|
|
|
|
|
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"
|
2006-12-06 20:44:07 +01:00
|
|
|
#include "cygwin/version.h"
|
2001-11-15 04:25:52 +01:00
|
|
|
#include <stdlib.h>
|
2000-08-22 05:58:47 +02:00
|
|
|
#include "cygerrno.h"
|
2001-07-26 21:22:24 +02:00
|
|
|
#include "security.h"
|
2001-10-01 06:10:07 +02:00
|
|
|
#include "path.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 02:37:18 +02:00
|
|
|
#include "fhandler.h"
|
2000-08-22 07:10:20 +02:00
|
|
|
#include "dtable.h"
|
2001-04-18 23:10:15 +02:00
|
|
|
#include "cygheap.h"
|
2000-09-08 04:56:55 +02:00
|
|
|
#include "perprocess.h"
|
2004-02-12 04:01:58 +01:00
|
|
|
#include "cygtls.h"
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
/* tcsendbreak: POSIX 7.2.2.1 */
|
2000-09-07 18:23:51 +02:00
|
|
|
extern "C" int
|
2000-02-17 20:38:33 +01:00
|
|
|
tcsendbreak (int fd, int duration)
|
|
|
|
{
|
|
|
|
int res = -1;
|
|
|
|
|
2001-10-16 01:39:33 +02:00
|
|
|
cygheap_fdget cfd (fd);
|
|
|
|
if (cfd < 0)
|
|
|
|
goto out;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2001-10-16 01:39:33 +02:00
|
|
|
if (!cfd->is_tty ())
|
2000-02-17 20:38:33 +01:00
|
|
|
set_errno (ENOTTY);
|
2001-10-16 01:39:33 +02:00
|
|
|
else if ((res = cfd->bg_check (-SIGTTOU)) > bg_eof)
|
|
|
|
res = cfd->tcsendbreak (duration);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
out:
|
2011-12-03 22:43:27 +01:00
|
|
|
syscall_printf ("%R = tcsendbreak(%d, %d)", res, fd, duration);
|
2000-02-17 20:38:33 +01:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* tcdrain: POSIX 7.2.2.1 */
|
2000-09-07 18:23:51 +02:00
|
|
|
extern "C" int
|
2000-02-17 20:38:33 +01:00
|
|
|
tcdrain (int fd)
|
|
|
|
{
|
2011-04-30 18:34:48 +02:00
|
|
|
pthread_testcancel ();
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
int res = -1;
|
|
|
|
|
|
|
|
termios_printf ("tcdrain");
|
|
|
|
|
2001-10-16 01:39:33 +02:00
|
|
|
cygheap_fdget cfd (fd);
|
|
|
|
if (cfd < 0)
|
|
|
|
goto out;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2001-10-16 01:39:33 +02:00
|
|
|
if (!cfd->is_tty ())
|
2000-02-17 20:38:33 +01:00
|
|
|
set_errno (ENOTTY);
|
2001-10-16 01:39:33 +02:00
|
|
|
else if ((res = cfd->bg_check (-SIGTTOU)) > bg_eof)
|
|
|
|
res = cfd->tcdrain ();
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
out:
|
2011-12-03 22:43:27 +01:00
|
|
|
syscall_printf ("%R = tcdrain(%d)", res, fd);
|
2000-02-17 20:38:33 +01:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* tcflush: POSIX 7.2.2.1 */
|
2000-09-07 18:23:51 +02:00
|
|
|
extern "C" int
|
2000-02-17 20:38:33 +01:00
|
|
|
tcflush (int fd, int queue)
|
|
|
|
{
|
|
|
|
int res = -1;
|
|
|
|
|
2001-10-16 01:39:33 +02:00
|
|
|
cygheap_fdget cfd (fd);
|
|
|
|
if (cfd < 0)
|
|
|
|
goto out;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2001-10-16 01:39:33 +02:00
|
|
|
if (!cfd->is_tty ())
|
2000-02-17 20:38:33 +01:00
|
|
|
set_errno (ENOTTY);
|
2003-09-18 20:54:48 +02:00
|
|
|
else if (queue != TCIFLUSH && queue != TCOFLUSH && queue != TCIOFLUSH)
|
|
|
|
set_errno (EINVAL);
|
2001-10-16 01:39:33 +02:00
|
|
|
else if ((res = cfd->bg_check (-SIGTTOU)) > bg_eof)
|
|
|
|
res = cfd->tcflush (queue);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
out:
|
2011-12-03 22:43:27 +01:00
|
|
|
termios_printf ("%R = tcflush(%d, %d)", res, fd, queue);
|
2000-02-17 20:38:33 +01:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* tcflow: POSIX 7.2.2.1 */
|
2000-09-07 18:23:51 +02:00
|
|
|
extern "C" int
|
2000-02-17 20:38:33 +01:00
|
|
|
tcflow (int fd, int action)
|
|
|
|
{
|
|
|
|
int res = -1;
|
|
|
|
|
2001-10-16 01:39:33 +02:00
|
|
|
cygheap_fdget cfd (fd);
|
|
|
|
if (cfd < 0)
|
|
|
|
goto out;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2001-10-16 01:39:33 +02:00
|
|
|
if (!cfd->is_tty ())
|
2000-02-17 20:38:33 +01:00
|
|
|
set_errno (ENOTTY);
|
2001-10-16 01:39:33 +02:00
|
|
|
else if ((res = cfd->bg_check (-SIGTTOU)) > bg_eof)
|
|
|
|
res = cfd->tcflow (action);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
out:
|
2011-12-03 22:43:27 +01:00
|
|
|
syscall_printf ("%R = tcflow(%d, %d)", res, fd, action);
|
2000-02-17 20:38:33 +01:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* tcsetattr: POSIX96 7.2.1.1 */
|
2000-09-07 18:23:51 +02:00
|
|
|
extern "C" int
|
2000-02-17 20:38:33 +01:00
|
|
|
tcsetattr (int fd, int a, const struct termios *t)
|
|
|
|
{
|
2002-07-29 05:18:41 +02:00
|
|
|
int res;
|
2001-08-23 04:27:01 +02:00
|
|
|
t = __tonew_termios (t);
|
2002-07-29 05:18:41 +02:00
|
|
|
int e = get_errno ();
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
res = -1;
|
|
|
|
cygheap_fdget cfd (fd);
|
|
|
|
if (cfd < 0)
|
|
|
|
{
|
|
|
|
e = get_errno ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cfd->is_tty ())
|
|
|
|
{
|
|
|
|
e = ENOTTY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = cfd->bg_check (-SIGTTOU);
|
|
|
|
|
|
|
|
switch (res)
|
|
|
|
{
|
|
|
|
case bg_eof:
|
|
|
|
e = get_errno ();
|
|
|
|
break;
|
|
|
|
case bg_ok:
|
|
|
|
if (cfd.isopen ())
|
|
|
|
res = cfd->tcsetattr (a, t);
|
2003-02-01 05:48:03 +01:00
|
|
|
e = get_errno ();
|
2002-07-29 05:18:41 +02:00
|
|
|
break;
|
|
|
|
case bg_signalled:
|
2004-02-12 04:01:58 +01:00
|
|
|
if (_my_tls.call_signal_handler ())
|
2002-07-29 05:18:41 +02:00
|
|
|
continue;
|
|
|
|
res = -1;
|
|
|
|
/* fall through intentionally */
|
|
|
|
default:
|
|
|
|
e = get_errno ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
set_errno (e);
|
2013-04-23 11:44:36 +02:00
|
|
|
termios_printf ("iflag %y, oflag %y, cflag %y, lflag %y, VMIN %d, VTIME %d",
|
2000-02-17 20:38:33 +01:00
|
|
|
t->c_iflag, t->c_oflag, t->c_cflag, t->c_lflag, t->c_cc[VMIN],
|
|
|
|
t->c_cc[VTIME]);
|
2013-04-23 11:44:36 +02:00
|
|
|
termios_printf ("%R = tcsetattr(%d, %d, %p)", res, fd, a, t);
|
2000-02-17 20:38:33 +01:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* tcgetattr: POSIX 7.2.1.1 */
|
2000-09-07 18:23:51 +02:00
|
|
|
extern "C" int
|
2000-02-17 20:38:33 +01:00
|
|
|
tcgetattr (int fd, struct termios *in_t)
|
|
|
|
{
|
|
|
|
int res = -1;
|
|
|
|
struct termios *t = __makenew_termios (in_t);
|
|
|
|
|
2001-10-16 01:39:33 +02:00
|
|
|
cygheap_fdget cfd (fd);
|
|
|
|
if (cfd < 0)
|
|
|
|
/* saw an error */;
|
|
|
|
else if (!cfd->is_tty ())
|
2000-02-17 20:38:33 +01:00
|
|
|
set_errno (ENOTTY);
|
2001-10-16 01:39:33 +02:00
|
|
|
else if ((res = cfd->tcgetattr (t)) == 0)
|
2005-09-09 05:00:34 +02:00
|
|
|
__toapp_termios (in_t, t);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
if (res)
|
2011-12-03 22:43:27 +01:00
|
|
|
termios_printf ("%R = tcgetattr(%d, %p)", res, fd, in_t);
|
2000-02-17 20:38:33 +01:00
|
|
|
else
|
2013-04-23 11:44:36 +02:00
|
|
|
termios_printf ("iflag %y, oflag %y, cflag %y, lflag %y, VMIN %d, VTIME %d",
|
2000-02-17 20:38:33 +01:00
|
|
|
t->c_iflag, t->c_oflag, t->c_cflag, t->c_lflag, t->c_cc[VMIN],
|
|
|
|
t->c_cc[VTIME]);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* tcgetpgrp: POSIX 7.2.3.1 */
|
2000-09-07 18:23:51 +02:00
|
|
|
extern "C" int
|
2000-02-17 20:38:33 +01:00
|
|
|
tcgetpgrp (int fd)
|
|
|
|
{
|
2011-10-12 01:20:38 +02:00
|
|
|
int res;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2001-10-16 01:39:33 +02:00
|
|
|
cygheap_fdget cfd (fd);
|
|
|
|
if (cfd < 0)
|
2011-10-12 01:20:38 +02:00
|
|
|
res = -1;
|
2000-02-17 20:38:33 +01:00
|
|
|
else
|
2001-10-16 01:39:33 +02:00
|
|
|
res = cfd->tcgetpgrp ();
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2011-12-03 22:43:27 +01:00
|
|
|
termios_printf ("%R = tcgetpgrp(%d)", res, fd);
|
2000-02-17 20:38:33 +01:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2012-02-28 15:03:03 +01:00
|
|
|
extern "C" pid_t
|
2011-10-12 01:20:38 +02:00
|
|
|
tcgetsid (int fd)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
|
|
|
|
cygheap_fdget cfd (fd);
|
|
|
|
if (cfd < 0)
|
|
|
|
res = -1;
|
|
|
|
else
|
|
|
|
res = cfd->tcgetsid ();
|
|
|
|
|
2011-12-03 22:43:27 +01:00
|
|
|
termios_printf ("%R = tcgetsid(%d)", res, fd);
|
2011-10-12 01:20:38 +02:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
/* tcsetpgrp: POSIX 7.2.4.1 */
|
2000-09-07 18:23:51 +02:00
|
|
|
extern "C" int
|
2000-02-17 20:38:33 +01:00
|
|
|
tcsetpgrp (int fd, pid_t pgid)
|
|
|
|
{
|
|
|
|
int res = -1;
|
|
|
|
|
2001-10-16 01:39:33 +02:00
|
|
|
cygheap_fdget cfd (fd);
|
|
|
|
if (cfd < 0)
|
|
|
|
/* saw an error */;
|
|
|
|
else if (!cfd->is_tty ())
|
2000-02-17 20:38:33 +01:00
|
|
|
set_errno (ENOTTY);
|
|
|
|
else
|
2001-10-16 01:39:33 +02:00
|
|
|
res = cfd->tcsetpgrp (pgid);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2011-12-03 22:43:27 +01:00
|
|
|
termios_printf ("%R = tcsetpgrp(%d, %d)", res, fd, pgid);
|
2000-02-17 20:38:33 +01:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* NIST PCTS requires not macro-only implementation */
|
|
|
|
#undef cfgetospeed
|
|
|
|
#undef cfgetispeed
|
|
|
|
#undef cfsetospeed
|
|
|
|
#undef cfsetispeed
|
|
|
|
|
|
|
|
/* cfgetospeed: POSIX96 7.1.3.1 */
|
2000-09-07 18:23:51 +02:00
|
|
|
extern "C" speed_t
|
2011-01-11 11:09:23 +01:00
|
|
|
cfgetospeed (const struct termios *tp)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2002-09-22 05:38:57 +02:00
|
|
|
return __tonew_termios (tp)->c_ospeed;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* cfgetispeed: POSIX96 7.1.3.1 */
|
2000-09-07 18:23:51 +02:00
|
|
|
extern "C" speed_t
|
2011-01-11 11:09:23 +01:00
|
|
|
cfgetispeed (const struct termios *tp)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2002-09-22 05:38:57 +02:00
|
|
|
return __tonew_termios (tp)->c_ispeed;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2003-04-16 05:03:45 +02:00
|
|
|
static inline int
|
|
|
|
setspeed (speed_t &set_speed, speed_t from_speed)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
switch (from_speed)
|
|
|
|
{
|
|
|
|
case B0:
|
|
|
|
case B50:
|
|
|
|
case B75:
|
|
|
|
case B110:
|
|
|
|
case B134:
|
|
|
|
case B150:
|
|
|
|
case B200:
|
|
|
|
case B300:
|
|
|
|
case B600:
|
|
|
|
case B1200:
|
|
|
|
case B1800:
|
|
|
|
case B2400:
|
|
|
|
case B4800:
|
|
|
|
case B9600:
|
|
|
|
case B19200:
|
|
|
|
case B38400:
|
|
|
|
case B57600:
|
|
|
|
case B115200:
|
|
|
|
case B128000:
|
|
|
|
case B230400:
|
|
|
|
case B256000:
|
2007-09-26 10:57:35 +02:00
|
|
|
case B460800:
|
|
|
|
case B500000:
|
|
|
|
case B576000:
|
|
|
|
case B921600:
|
|
|
|
case B1000000:
|
|
|
|
case B1152000:
|
|
|
|
case B1500000:
|
|
|
|
case B2000000:
|
|
|
|
case B2500000:
|
|
|
|
case B3000000:
|
2003-04-16 05:03:45 +02:00
|
|
|
set_speed = from_speed;
|
|
|
|
res = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
set_errno (EINVAL);
|
|
|
|
res = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
/* cfsetospeed: POSIX96 7.1.3.1 */
|
2000-09-07 18:23:51 +02:00
|
|
|
extern "C" int
|
2000-02-17 20:38:33 +01:00
|
|
|
cfsetospeed (struct termios *in_tp, speed_t speed)
|
|
|
|
{
|
|
|
|
struct termios *tp = __tonew_termios (in_tp);
|
2003-04-16 05:03:45 +02:00
|
|
|
int res = setspeed (tp->c_ospeed, speed);
|
2005-07-06 22:05:03 +02:00
|
|
|
__toapp_termios (in_tp, tp);
|
2003-04-16 05:03:45 +02:00
|
|
|
return res;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* cfsetispeed: POSIX96 7.1.3.1 */
|
2000-09-07 18:23:51 +02:00
|
|
|
extern "C" int
|
2000-02-17 20:38:33 +01:00
|
|
|
cfsetispeed (struct termios *in_tp, speed_t speed)
|
|
|
|
{
|
|
|
|
struct termios *tp = __tonew_termios (in_tp);
|
2003-04-16 05:03:45 +02:00
|
|
|
int res = setspeed (tp->c_ispeed, speed);
|
2005-07-06 22:05:03 +02:00
|
|
|
__toapp_termios (in_tp, tp);
|
2003-04-16 05:03:45 +02:00
|
|
|
return res;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
2008-09-13 00:32:07 +02:00
|
|
|
|
2012-11-21 21:13:07 +01:00
|
|
|
/* cfsetspeed: 4.4BSD */
|
|
|
|
extern "C" int
|
|
|
|
cfsetspeed (struct termios *in_tp, speed_t speed)
|
|
|
|
{
|
|
|
|
struct termios *tp = __tonew_termios (in_tp);
|
|
|
|
int res;
|
|
|
|
/* errors come only from unsupported baud rates, so setspeed() would return
|
|
|
|
identical results in both calls */
|
|
|
|
if ((res = setspeed (tp->c_ospeed, speed)) == 0)
|
|
|
|
setspeed (tp->c_ispeed, speed);
|
|
|
|
__toapp_termios (in_tp, tp);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2008-09-13 00:32:07 +02:00
|
|
|
extern "C" void
|
|
|
|
cfmakeraw(struct termios *tp)
|
|
|
|
{
|
|
|
|
tp->c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP
|
|
|
|
| INLCR | IGNCR | ICRNL | IXON);
|
|
|
|
tp->c_oflag &= ~OPOST;
|
|
|
|
tp->c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
|
|
|
|
tp->c_cflag &= ~(CSIZE | PARENB);
|
|
|
|
tp->c_cflag |= CS8;
|
|
|
|
}
|