newlib-cygwin/winsup/cygwin/ioctl.cc

59 lines
1.3 KiB
C++
Raw Normal View History

2000-02-18 03:38:33 +08:00
/* ioctl.cc: ioctl routines.
2002-01-14 04:03:03 +08:00
Copyright 1996, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
2000-02-18 03:38:33 +08:00
Written by Doug Evans of Cygnus Support
dje@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"
2000-02-18 03:38:33 +08:00
#include <sys/ioctl.h>
#include <errno.h>
#include "cygerrno.h"
#include "security.h"
#include "fhandler.h"
Add "path.h" include throughout, where needed. Use new path_conv methods and operators to simplify testing for directory and attributes, throughout. * path.h (path_conv::exists): New method. (path_conv::has_attribute): Ditto. (path_conv::isdir): Ditto. (path_conv::DWORD &): New operator. (path_conv::int &): Ditto. * dir.cc (rmdir): Eliminate a goto. * dtable.cc (dtable::build_fhandler): Accept opt and suffix info for path_conv.check. Return fh == NULL on path_conv error. Pass unit to set_name as appropriate. (dtable::reset_unix_path_name): New method. * dtable.h (dtable): Declare new method. Reflect arg changes to build_fhandler. * fhandler.cc (fhandler_disk_dummy_name): Eliminate. (fhandler_base::set_name): Expect paths to be NULL. Build unix_path_name from win32_path_name when it is a device. (fhandler_base::reset_unix_path_name): New method. (fhandler_base::raw_read): Report EISDIR when ERROR_INVALID_FUNCTION or ERROR_INVALID_PARAMETER and reading a directory. (fhandler_disk_file::fstat): Don't call stat_dev since we should now never be calling fhandler_disk_file methods with devices. (fhandler_base::fhandler_base): Clear {unix,win32}_path_name. (fhandler_base::~fhandler_base): Always free {unix,win32}_path_name. (fhandler_disk_file::fhandler_disk_file): Remove set_no_free_names kludge. (fhandler_disk_file::open): Ditto. * fhandler.h (fhandler_base::no_free_names): Eliminate. (fhandler_base::set_no_free_names): Ditto. * fhandler_tty.cc (fhandler_tty_slave::fhandler_tty_slave): Don't set unix_path_name here. * path.cc (fchdir): Lock fd table throughout. Use new dtable::reset_unix_path_name method to reset path. * syscalls.cc (stat_worker): Reorganize to always call fstat method. Pass path_conv method to fhandler_*::open. (chroot): Elminate a goto.
2001-10-01 12:10:07 +08:00
#include "path.h"
#include "dtable.h"
#include "cygheap.h"
#include "sigproc.h"
#include <sys/termios.h>
2000-02-18 03:38:33 +08:00
extern "C" int
ioctl (int fd, int cmd, ...)
2000-02-18 03:38:33 +08:00
{
sigframe thisframe (mainthread);
cygheap_fdget cfd (fd);
if (cfd < 0)
return -1;
2000-02-18 03:38:33 +08:00
/* check for optional mode argument */
va_list ap;
va_start (ap, cmd);
char *argp = va_arg (ap, char *);
va_end (ap);
debug_printf ("fd %d, cmd %x", fd, cmd);
if (cfd->is_tty () && cfd->get_device () != FH_PTYM)
2000-02-18 03:38:33 +08:00
switch (cmd)
{
case TCGETA:
return tcgetattr (fd, (struct termios *) argp);
2000-02-18 03:38:33 +08:00
case TCSETA:
return tcsetattr (fd, TCSANOW, (struct termios *) argp);
2000-02-18 03:38:33 +08:00
case TCSETAW:
return tcsetattr (fd, TCSADRAIN, (struct termios *) argp);
2000-02-18 03:38:33 +08:00
case TCSETAF:
return tcsetattr (fd, TCSAFLUSH, (struct termios *) argp);
2000-02-18 03:38:33 +08:00
}
int res = cfd->ioctl (cmd, argp);
debug_printf ("returning %d", res);
return res;
2000-02-18 03:38:33 +08:00
}