* dtable.cc (dtable::dup2): Allow extension of fd table by dup2.

* syscalls.cc: Minor code cleanup.
(fpathconf): Check for bad fd before doing anything else.
* termios.cc (tcsetattr): Don't convert to new termios if bad fd.
(tcgetattr): Minor debugging tweak.
This commit is contained in:
Christopher Faylor 2001-08-23 02:27:01 +00:00
parent cb19ccf4b5
commit ecaff08ccd
4 changed files with 28 additions and 24 deletions

View File

@ -1,3 +1,11 @@
Wed Aug 22 22:23:14 2001 Christopher Faylor <cgf@cygnus.com>
* dtable.cc (dtable::dup2): Allow extension of fd table by dup2.
* syscalls.cc: Minor code cleanup.
(fpathconf): Check for bad fd before doing anything else.
* termios.cc (tcsetattr): Don't convert to new termios if bad fd.
(tcgetattr): Minor debugging tweak.
Wed Aug 22 23:41:00 2001 Corinna Vinschen <corinna@vinschen.de> Wed Aug 22 23:41:00 2001 Corinna Vinschen <corinna@vinschen.de>
* net.cc (cygwin_inet_ntoa): Rearrange previous patch to use * net.cc (cygwin_inet_ntoa): Rearrange previous patch to use

View File

@ -386,7 +386,7 @@ dtable::dup2 (int oldfd, int newfd)
SetResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK,"dup"); SetResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK,"dup");
if ((size_t) newfd >= cygheap->fdtab.size || newfd < 0) if (newfd < 0)
{ {
syscall_printf ("new fd out of bounds: %d", newfd); syscall_printf ("new fd out of bounds: %d", newfd);
set_errno (EBADF); set_errno (EBADF);

View File

@ -1494,6 +1494,11 @@ check_posix_perm (const char *fname, int v)
extern "C" long int extern "C" long int
fpathconf (int fd, int v) fpathconf (int fd, int v)
{ {
if (cygheap->fdtab.not_open (fd))
{
set_errno (EBADF);
return -1;
}
switch (v) switch (v)
{ {
case _PC_LINK_MAX: case _PC_LINK_MAX:
@ -1525,16 +1530,13 @@ fpathconf (int fd, int v)
} }
case _PC_POSIX_PERMISSIONS: case _PC_POSIX_PERMISSIONS:
case _PC_POSIX_SECURITY: case _PC_POSIX_SECURITY:
if (cygheap->fdtab.not_open (fd)) {
set_errno (EBADF); fhandler_base *fh = cygheap->fdtab[fd];
else if (fh->get_device () == FH_DISK)
{ return check_posix_perm (fh->get_win32_name (), v);
fhandler_base *fh = cygheap->fdtab[fd]; set_errno (EINVAL);
if (fh->get_device () == FH_DISK) return -1;
return check_posix_perm (fh->get_win32_name (), v); }
set_errno (EINVAL);
}
return -1;
default: default:
set_errno (EINVAL); set_errno (EINVAL);
return -1; return -1;
@ -1772,7 +1774,6 @@ ftruncate (int fd, off_t length)
} }
/* truncate: Provided by SVR4 and 4.3+BSD. Not part of POSIX.1 or XPG3 */ /* truncate: Provided by SVR4 and 4.3+BSD. Not part of POSIX.1 or XPG3 */
/* FIXME: untested */
extern "C" int extern "C" int
truncate (const char *pathname, off_t length) truncate (const char *pathname, off_t length)
{ {
@ -1783,9 +1784,7 @@ truncate (const char *pathname, off_t length)
fd = open (pathname, O_RDWR); fd = open (pathname, O_RDWR);
if (fd == -1) if (fd == -1)
{ set_errno (EBADF);
set_errno (EBADF);
}
else else
{ {
res = ftruncate (fd, length); res = ftruncate (fd, length);
@ -1802,15 +1801,11 @@ get_osfhandle (int fd)
long res = -1; long res = -1;
if (cygheap->fdtab.not_open (fd)) if (cygheap->fdtab.not_open (fd))
{ set_errno (EBADF);
set_errno (EBADF);
}
else else
{ res = (long) cygheap->fdtab[fd]->get_handle ();
res = (long) cygheap->fdtab[fd]->get_handle ();
}
syscall_printf ("%d = get_osfhandle (%d)", res, fd);
syscall_printf ("%d = get_osfhandle (%d)", res, fd);
return res; return res;
} }

View File

@ -143,13 +143,14 @@ tcsetattr (int fd, int a, const struct termios *t)
{ {
int res = -1; int res = -1;
t = __tonew_termios (t);
if (cygheap->fdtab.not_open (fd)) if (cygheap->fdtab.not_open (fd))
{ {
set_errno (EBADF); set_errno (EBADF);
goto out; goto out;
} }
t = __tonew_termios (t);
fhandler_base *fh; fhandler_base *fh;
fh = cygheap->fdtab[fd]; fh = cygheap->fdtab[fd];
@ -187,7 +188,7 @@ tcgetattr (int fd, struct termios *in_t)
} }
if (res) if (res)
termios_printf ("%d = tcgetattr (%d, %x)", res, fd, in_t); termios_printf ("%d = tcgetattr (%d, %p)", res, fd, in_t);
else else
termios_printf ("iflag %x, oflag %x, cflag %x, lflag %x, VMIN %d, VTIME %d", termios_printf ("iflag %x, oflag %x, cflag %x, lflag %x, VMIN %d, VTIME %d",
t->c_iflag, t->c_oflag, t->c_cflag, t->c_lflag, t->c_cc[VMIN], t->c_iflag, t->c_oflag, t->c_cflag, t->c_lflag, t->c_cc[VMIN],