+Sat Aug 12 00:47:11 2000 Christopher Faylor <cgf@cygnus.com>
+
+ Rename hinfo -> dtable. Name the former dtable array 'fdtab'.
+
Fri Aug 11 14:47:00 2000 Corinna Vinschen <corinna@vinschen.de>
* poll.cc: Allow any descriptor and any number of descriptors.
set_console_title (cp);
}
- /* Allocate dtable */
- dtable_init ();
+ /* Allocate fdtab */
+ fdtab_init ();
/* Initialize uid, gid. */
uinfo_init ();
tty_init ();
/* Set up standard fds in file descriptor table. */
- hinfo_init ();
+ stdio_init ();
if (user_data->premain[0])
for (unsigned int i = 0; i < PREMAIN_LEN / 2; i++)
-/* hinfo.cc: file descriptor support.
+/* dtable.cc: file descriptor support.
Copyright 1996, 1997, 1998, 1999, 2000 Cygnus Solutions.
#include <winsock.h>
-hinfo dtable;
+dtable fdtab;
/* Set aside space for the table of fds */
void
-dtable_init (void)
+fdtab_init (void)
{
- if (!dtable.size)
- dtable.extend(NOFILE_INCR);
+ if (!fdtab.size)
+ fdtab.extend(NOFILE_INCR);
}
void __stdcall
set_std_handle (int fd)
{
if (fd == 0)
- SetStdHandle (STD_INPUT_HANDLE, dtable[fd]->get_handle ());
+ SetStdHandle (STD_INPUT_HANDLE, fdtab[fd]->get_handle ());
else if (fd == 1)
- SetStdHandle (STD_OUTPUT_HANDLE, dtable[fd]->get_output_handle ());
+ SetStdHandle (STD_OUTPUT_HANDLE, fdtab[fd]->get_output_handle ());
else if (fd == 2)
- SetStdHandle (STD_ERROR_HANDLE, dtable[fd]->get_output_handle ());
+ SetStdHandle (STD_ERROR_HANDLE, fdtab[fd]->get_output_handle ());
}
int
-hinfo::extend (int howmuch)
+dtable::extend (int howmuch)
{
int new_size = size + howmuch;
fhandler_base **newfds;
initialized at each fork () call. */
void
-hinfo_init (void)
+stdio_init (void)
{
/* Set these before trying to output anything from strace.
Also, always set them even if we're to pick up our parent's fds
HANDLE out = GetStdHandle (STD_OUTPUT_HANDLE);
HANDLE err = GetStdHandle (STD_ERROR_HANDLE);
- dtable.init_std_file_from_handle (0, in, GENERIC_READ, "{stdin}");
+ fdtab.init_std_file_from_handle (0, in, GENERIC_READ, "{stdin}");
/* STD_ERROR_HANDLE has been observed to be the same as
STD_OUTPUT_HANDLE. We need separate handles (e.g. using pipes
}
}
- dtable.init_std_file_from_handle (1, out, GENERIC_WRITE, "{stdout}");
- dtable.init_std_file_from_handle (2, err, GENERIC_WRITE, "{stderr}");
+ fdtab.init_std_file_from_handle (1, out, GENERIC_WRITE, "{stdout}");
+ fdtab.init_std_file_from_handle (2, err, GENERIC_WRITE, "{stderr}");
}
}
int
-hinfo::not_open (int fd)
+dtable::not_open (int fd)
{
SetResourceLock(LOCK_FD_LIST,READ_LOCK," not_open");
}
int
-hinfo::find_unused_handle (int start)
+dtable::find_unused_handle (int start)
{
AssertResourceOwner(LOCK_FD_LIST, READ_LOCK);
}
void
-hinfo::release (int fd)
+dtable::release (int fd)
{
if (!not_open (fd))
{
}
void
-hinfo::init_std_file_from_handle (int fd, HANDLE handle,
+dtable::init_std_file_from_handle (int fd, HANDLE handle,
DWORD myaccess, const char *name)
{
int bin = binmode ? O_BINARY : 0;
DWORD myaccess)
{
if (fd == -1)
- fd = dtable.find_unused_handle();
- fhandler_base *res = dtable.build_fhandler (fd, name, handle);
+ fd = fdtab.find_unused_handle();
+ fhandler_base *res = fdtab.build_fhandler (fd, name, handle);
res->init (handle, myaccess, bin);
return fd;
}
fhandler_base *
-hinfo::build_fhandler (int fd, const char *name, HANDLE handle)
+dtable::build_fhandler (int fd, const char *name, HANDLE handle)
{
int unit;
DWORD devn;
}
fhandler_base *
-hinfo::build_fhandler (int fd, DWORD dev, const char *name, int unit)
+dtable::build_fhandler (int fd, DWORD dev, const char *name, int unit)
{
fhandler_base *fh;
void *buf = calloc (1, sizeof (fhandler_union) + 100);
}
fhandler_base *
-hinfo::dup_worker (fhandler_base *oldfh)
+dtable::dup_worker (fhandler_base *oldfh)
{
fhandler_base *newfh = build_fhandler (-1, oldfh->get_device (), NULL);
*newfh = *oldfh;
}
int
-hinfo::dup2 (int oldfd, int newfd)
+dtable::dup2 (int oldfd, int newfd)
{
int res = -1;
fhandler_base *newfh = NULL; // = NULL to avoid an incorrect warning
}
SetResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK,"dup");
- if ((size_t) newfd >= dtable.size || newfd < 0)
+ if ((size_t) newfd >= fdtab.size || newfd < 0)
{
syscall_printf ("new fd out of bounds: %d", newfd);
set_errno (EBADF);
}
select_record *
-hinfo::select_read (int fd, select_record *s)
+dtable::select_read (int fd, select_record *s)
{
- if (dtable.not_open (fd))
+ if (fdtab.not_open (fd))
{
set_errno (EBADF);
return NULL;
}
- fhandler_base *fh = dtable[fd];
+ fhandler_base *fh = fdtab[fd];
s = fh->select_read (s);
s->fd = fd;
s->fh = fh;
}
select_record *
-hinfo::select_write (int fd, select_record *s)
+dtable::select_write (int fd, select_record *s)
{
- if (dtable.not_open (fd))
+ if (fdtab.not_open (fd))
{
set_errno (EBADF);
return NULL;
}
- fhandler_base *fh = dtable[fd];
+ fhandler_base *fh = fdtab[fd];
s = fh->select_write (s);
s->fd = fd;
s->fh = fh;
}
select_record *
-hinfo::select_except (int fd, select_record *s)
+dtable::select_except (int fd, select_record *s)
{
- if (dtable.not_open (fd))
+ if (fdtab.not_open (fd))
{
set_errno (EBADF);
return NULL;
}
- fhandler_base *fh = dtable[fd];
+ fhandler_base *fh = fdtab[fd];
s = fh->select_except (s);
s->fd = fd;
s->fh = fh;
}
/*
- * Function to take an existant hinfo array
+ * Function to take an existant dtable array
* and linearize it into a memory buffer.
* If memory buffer is NULL, it returns the size
* of memory buffer needed to do the linearization.
*/
int
-hinfo::linearize_fd_array (unsigned char *in_buf, int buflen)
+dtable::linearize_fd_array (unsigned char *in_buf, int buflen)
{
/* If buf == NULL, just precalculate length */
if (in_buf == NULL)
}
/*
- * Function to take a linearized hinfo array in a memory buffer and
- * re-create the original hinfo array.
+ * Function to take a linearized dtable array in a memory buffer and
+ * re-create the original dtable array.
*/
LPBYTE
-hinfo::de_linearize_fd_array (LPBYTE buf)
+dtable::de_linearize_fd_array (LPBYTE buf)
{
int len, max_used_fd;
size_t inc_size;
debug_printf ("buf %x", buf);
- /* First get the number of fd's - use this to set the dtablesize.
+ /* First get the number of fd's - use this to set the fdtabsize.
NB. This is the only place in the code this should be done !!
*/
}
void
-hinfo::fixup_after_fork (HANDLE parent)
+dtable::fixup_after_fork (HANDLE parent)
{
SetResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK,"dup");
for (size_t i = 0; i < size; i++)
}
int
-hinfo::vfork_child_dup ()
+dtable::vfork_child_dup ()
{
fhandler_base **newtable;
newtable = (fhandler_base **) calloc (size, sizeof(fds[0]));
}
void
-hinfo::vfork_parent_restore ()
+dtable::vfork_parent_restore ()
{
SetResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK,"dup");
int res;
SetResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK, "_fcntl");
- if (dtable.not_open (fd))
+ if (fdtab.not_open (fd))
{
set_errno (EBADF);
res = -1;
va_start (args, cmd);
arg = va_arg (args,int);
va_end (args);
- res = dup2 (fd, dtable.find_unused_handle (arg));
+ res = dup2 (fd, fdtab.find_unused_handle (arg));
goto done;
case F_GETFD:
- res = dtable[fd]->get_close_on_exec () ? FD_CLOEXEC : 0;
+ res = fdtab[fd]->get_close_on_exec () ? FD_CLOEXEC : 0;
goto done;
case F_SETFD:
va_start (args, cmd);
arg = va_arg (args, int);
va_end (args);
- dtable[fd]->set_close_on_exec (arg);
+ fdtab[fd]->set_close_on_exec (arg);
res = 0;
goto done;
case F_GETFL:
{
- res = dtable[fd]->get_flags ();
+ res = fdtab[fd]->get_flags ();
goto done;
}
case F_SETFL:
syscall_printf ("fcntl (%d, F_SETFL, %d)", arg);
- dtable[fd]->set_access (temp);
- dtable[fd]->set_flags (arg);
+ fdtab[fd]->set_access (temp);
+ fdtab[fd]->set_flags (arg);
res = 0;
goto done;
va_start (args, cmd);
fl = va_arg (args,struct flock *);
va_end (args);
- res = dtable[fd]->lock (cmd, fl);
+ res = fdtab[fd]->lock (cmd, fl);
goto done;
}
default:
int
fhandler_tty_master::init_console ()
{
- console = (fhandler_console *) dtable.build_fhandler (-1, FH_CONSOLE, "/dev/ttym");
+ console = (fhandler_console *) fdtab.build_fhandler (-1, FH_CONSOLE, "/dev/ttym");
if (console == NULL)
return -1;
MALLOC_CHECK;
- dtable.fixup_after_fork (hParent);
+ fdtab.fixup_after_fork (hParent);
signal_fixup_after_fork ();
exec_fixup_after_fork ();
for (pp = (char **)vf->frame, esp = vf->vfork_esp;
esp <= vf->vfork_ebp + 1; pp++, esp++)
*pp = *esp;
- return dtable.vfork_child_dup () ? 0 : -1;
+ return fdtab.vfork_child_dup () ? 0 : -1;
}
- dtable.vfork_parent_restore ();
+ fdtab.vfork_parent_restore ();
vf = get_vfork_val ();
if (vf->pid < 0)
int
ioctl (int fd, int cmd, void *buf)
{
- if (dtable.not_open (fd))
+ if (fdtab.not_open (fd))
{
set_errno (EBADF);
return -1;
}
debug_printf ("fd %d, cmd %x\n", fd, cmd);
- fhandler_base *fh = dtable[fd];
+ fhandler_base *fh = fdtab[fd];
if (fh->is_tty () && fh->get_device () != FH_PTYM)
switch (cmd)
{
else
{
/* Ensure that fd is open */
- if (dtable.not_open (fd))
+ if (fdtab.not_open (fd))
{
set_errno (EBADF);
syscall_printf ("-1 = mmap(): EBADF");
ReleaseResourceLock(LOCK_MMAP_LIST,READ_LOCK|WRITE_LOCK," mmap");
return (caddr_t) -1;
}
- hFile = dtable[fd]->get_handle ();
+ hFile = fdtab[fd]->get_handle ();
}
HANDLE h = CreateFileMapping (hFile, &sec_none, protect, 0, len, NULL);
void
fdsock (int fd, const char *name, SOCKET soc)
{
- fhandler_base *fh = dtable.build_fhandler(fd, FH_SOCKET, name);
+ fhandler_base *fh = fdtab.build_fhandler(fd, FH_SOCKET, name);
fh->set_io_handle ((HANDLE) soc);
fh->set_flags (O_RDWR);
}
SOCKET soc;
- int fd = dtable.find_unused_handle ();
+ int fd = fdtab.find_unused_handle ();
if (fd < 0)
{
fdsock (fd, name, soc);
res = fd;
- fhandler_socket *h = (fhandler_socket *) dtable[fd];
+ fhandler_socket *h = (fhandler_socket *) fdtab[fd];
h->set_addr_family (af);
}
const struct sockaddr *to,
int tolen)
{
- fhandler_socket *h = (fhandler_socket *) dtable[fd];
+ fhandler_socket *h = (fhandler_socket *) fdtab[fd];
sockaddr_in sin;
sigframe thisframe (mainthread, 0);
struct sockaddr *from,
int *fromlen)
{
- fhandler_socket *h = (fhandler_socket *) dtable[fd];
+ fhandler_socket *h = (fhandler_socket *) fdtab[fd];
sigframe thisframe (mainthread, 0);
debug_printf ("recvfrom %d", h->get_socket ());
fhandler_socket *
get (int fd)
{
- if (dtable.not_open (fd))
+ if (fdtab.not_open (fd))
{
set_errno (EINVAL);
return 0;
}
- return dtable[fd]->is_socket ();
+ return fdtab[fd]->is_socket ();
}
/* exported as setsockopt: standards? */
SetResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK," accept");
- int res_fd = dtable.find_unused_handle ();
+ int res_fd = fdtab.find_unused_handle ();
if (res_fd == -1)
{
/* FIXME: what is correct errno? */
int
cygwin_getpeername (int fd, struct sockaddr *name, int *len)
{
- fhandler_socket *h = (fhandler_socket *) dtable[fd];
+ fhandler_socket *h = (fhandler_socket *) fdtab[fd];
debug_printf ("getpeername %d", h->get_socket ());
int res = getpeername (h->get_socket (), name, len);
int
cygwin_recv (int fd, void *buf, int len, unsigned int flags)
{
- fhandler_socket *h = (fhandler_socket *) dtable[fd];
+ fhandler_socket *h = (fhandler_socket *) fdtab[fd];
sigframe thisframe (mainthread, 0);
int res = recv (h->get_socket (), (char *) buf, len, flags);
int
cygwin_send (int fd, const void *buf, int len, unsigned int flags)
{
- fhandler_socket *h = (fhandler_socket *) dtable[fd];
+ fhandler_socket *h = (fhandler_socket *) fdtab[fd];
sigframe thisframe (mainthread, 0);
int res = send (h->get_socket (), (const char *) buf, len, flags);
SOCKET fd2s;
sigframe thisframe (mainthread, 0);
- int res_fd = dtable.find_unused_handle ();
+ int res_fd = fdtab.find_unused_handle ();
if (res_fd == -1)
goto done;
if (fd2p)
{
- *fd2p = dtable.find_unused_handle (res_fd + 1);
+ *fd2p = fdtab.find_unused_handle (res_fd + 1);
if (*fd2p == -1)
goto done;
}
int res = -1;
sigframe thisframe (mainthread, 0);
- int res_fd = dtable.find_unused_handle ();
+ int res_fd = fdtab.find_unused_handle ();
if (res_fd == -1)
goto done;
res = rresvport (port);
SOCKET fd2s;
sigframe thisframe (mainthread, 0);
- int res_fd = dtable.find_unused_handle ();
+ int res_fd = fdtab.find_unused_handle ();
if (res_fd == -1)
goto done;
if (fd2p)
{
- *fd2p = dtable.find_unused_handle (res_fd + 1);
+ *fd2p = fdtab.find_unused_handle (res_fd + 1);
if (*fd2p == -1)
goto done;
}
SetResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK," socketpair");
- sb[0] = dtable.find_unused_handle ();
+ sb[0] = fdtab.find_unused_handle ();
if (sb[0] == -1)
{
set_errno (EMFILE);
goto done;
}
- sb[1] = dtable.find_unused_handle (sb[0] + 1);
+ sb[1] = fdtab.find_unused_handle (sb[0] + 1);
if (sb[1] == -1)
{
set_errno (EMFILE);
if (passwd_state == uninitialized)
read_etc_passwd();
- if (dtable.not_open (0))
+ if (fdtab.not_open (0))
{
set_errno (EBADF);
pass[0] = '\0';
}
else
{
- fhandler_base *fhstdin = dtable[0];
+ fhandler_base *fhstdin = fdtab[0];
fhstdin->tcgetattr (&ti);
newti = ti;
newti.c_lflag &= ~ECHO;
/* Inherit file descriptor information from parent in info.
*/
- LPBYTE b = dtable.de_linearize_fd_array (info);
+ LPBYTE b = fdtab.de_linearize_fd_array (info);
extern char title_buf[];
if (b && *b)
old_title = strcpy (title_buf, (char *)b);
int fdr, fdw;
SECURITY_ATTRIBUTES *sa = (mode & O_NOINHERIT) ? &sec_none_nih : &sec_none;
- if ((fdr = dtable.find_unused_handle ()) < 0)
+ if ((fdr = fdtab.find_unused_handle ()) < 0)
set_errno (ENMFILE);
- else if ((fdw = dtable.find_unused_handle (fdr + 1)) < 0)
+ else if ((fdw = fdtab.find_unused_handle (fdr + 1)) < 0)
set_errno ( ENMFILE);
else if (!CreatePipe (&r, &w, sa, psize))
__seterrno ();
else
{
- fhandler_base *fhr = dtable.build_fhandler (fdr, FH_PIPER, "/dev/piper");
- fhandler_base *fhw = dtable.build_fhandler (fdw, FH_PIPEW, "/dev/pipew");
+ fhandler_base *fhr = fdtab.build_fhandler (fdr, FH_PIPER, "/dev/piper");
+ fhandler_base *fhw = fdtab.build_fhandler (fdw, FH_PIPEW, "/dev/pipew");
int binmode = mode & O_TEXT ? 0 : 1;
fhr->init (r, GENERIC_READ, binmode);
int res = make_pipe (filedes, psize, mode);
/* This type of pipe is not interruptible so set the appropriate flag. */
if (!res)
- dtable[filedes[0]]->set_r_no_interrupt (1);
+ fdtab[filedes[0]]->set_r_no_interrupt (1);
return res;
}
int res;
SetResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK," dup");
- res = dup2 (fd, dtable.find_unused_handle ());
+ res = dup2 (fd, fdtab.find_unused_handle ());
ReleaseResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK," dup");
int
dup2 (int oldfd, int newfd)
{
- return dtable.dup2 (oldfd, newfd);
+ return fdtab.dup2 (oldfd, newfd);
}
memset (except_fds, 0, fds_size);
for (unsigned int i = 0; i < nfds; ++i)
- if (!dtable.not_open (fds[i].fd))
+ if (!fdtab.not_open (fds[i].fd))
{
FD_SET (fds[i].fd, open_fds);
if (fds[i].events & POLLIN)
{
if (!FD_ISSET (fds[i].fd, open_fds))
fds[i].revents = POLLNVAL;
- else if (dtable.not_open(fds[i].fd))
+ else if (fdtab.not_open(fds[i].fd))
fds[i].revents = POLLHUP;
else if (ret < 0)
fds[i].revents = POLLERR;
int
facl (int fd, int cmd, int nentries, aclent_t *aclbufp)
{
- if (dtable.not_open (fd))
+ if (fdtab.not_open (fd))
{
syscall_printf ("-1 = facl (%d)", fd);
set_errno (EBADF);
return -1;
}
- const char *path = dtable[fd]->get_name ();
+ const char *path = fdtab[fd]->get_name ();
if (path == NULL)
{
syscall_printf ("-1 = facl (%d) (no name)", fd);
me.fd = fd; \
(void) select_read (&me); \
while (!peek_##what (&me, ignra) && howlong == INFINITE) \
- if (fd >= 0 && dtable.not_open (fd)) \
+ if (fd >= 0 && fdtab.not_open (fd)) \
break; \
else if (WaitForSingleObject (signal_arrived, 10) == WAIT_OBJECT_0) \
break; \
#define set_handle_or_return_if_not_open(h, s) \
h = (s)->fh->get_handle (); \
- if (dtable.not_open ((s)->fd)) \
+ if (fdtab.not_open ((s)->fd)) \
{ \
(s)->saw_error = TRUE; \
set_errno (EBADF); \
fd_set *exceptfds)
{
select_record *s = NULL;
- if (UNIX_FD_ISSET (i, readfds) && (s = dtable.select_read (i, s)) == NULL)
+ if (UNIX_FD_ISSET (i, readfds) && (s = fdtab.select_read (i, s)) == NULL)
return 0; /* error */
- if (UNIX_FD_ISSET (i, writefds) && (s = dtable.select_write (i, s)) == NULL)
+ if (UNIX_FD_ISSET (i, writefds) && (s = fdtab.select_write (i, s)) == NULL)
return 0; /* error */
- if (UNIX_FD_ISSET (i, exceptfds) && (s = dtable.select_except (i, s)) == NULL)
+ if (UNIX_FD_ISSET (i, exceptfds) && (s = fdtab.select_except (i, s)) == NULL)
return 0; /* error */
if (s == NULL)
return 1; /* nothing to do */
static HANDLE
handle (int n, int direction)
{
- fhandler_base *fh = dtable[n];
+ fhandler_base *fh = fdtab[n];
if (!fh)
return INVALID_HANDLE_VALUE;
/* Pass fd table to a child */
MALLOC_CHECK;
- int len = dtable.linearize_fd_array (0, 0);
+ int len = fdtab.linearize_fd_array (0, 0);
MALLOC_CHECK;
if (len == -1)
{
LPBYTE resrv = si.lpReserved2 + sizeof *ciresrv;
# undef ciresrv
- if (dtable.linearize_fd_array (resrv, len) < 0)
+ if (fdtab.linearize_fd_array (resrv, len) < 0)
{
system_printf ("FATAL error in second linearize_fd_array");
return -1;
void __stdcall
close_all_files (void)
{
- for (int i = 0; i < (int)dtable.size; i++)
- if (!dtable.not_open (i))
+ for (int i = 0; i < (int)fdtab.size; i++)
+ if (!fdtab.not_open (i))
_close (i);
cygwin_shared->delqueue.process_queue ();
{
int res;
sigframe thisframe (mainthread);
- fhandler_base *fh = dtable[fd];
+ fhandler_base *fh = fdtab[fd];
- if (dtable.not_open (fd))
+ if (fdtab.not_open (fd))
{
set_errno (EBADF);
return -1;
extern "C" int
_read (int fd, void *ptr, size_t len)
{
- if (dtable.not_open (fd))
+ if (fdtab.not_open (fd))
{
set_errno (EBADF);
return -1;
}
set_sig_errno (0);
- fhandler_base *fh = dtable[fd];
+ fhandler_base *fh = fdtab[fd];
/* Could block, so let user know we at least got here. */
syscall_printf ("read (%d, %p, %d)", fd, ptr, len);
{
int res = -1;
- if (dtable.not_open (fd))
+ if (fdtab.not_open (fd))
{
set_errno (EBADF);
goto done;
syscall_printf ("write (%d, %p, %d)", fd, ptr, len);
fhandler_base *fh;
- fh = dtable[fd];
+ fh = fdtab[fd];
res = fh->bg_check (SIGTTOU);
if (res > 0)
mode = va_arg (ap, mode_t);
va_end (ap);
- fd = dtable.find_unused_handle ();
+ fd = fdtab.find_unused_handle ();
if (fd < 0)
set_errno (ENMFILE);
- else if ((fh = dtable.build_fhandler (fd, unix_path, NULL)) == NULL)
+ else if ((fh = fdtab.build_fhandler (fd, unix_path, NULL)) == NULL)
res = -1; // errno already set
else if (!fh->open (unix_path, flags, (mode & 0777) & ~myself->umask))
{
- dtable.release (fd);
+ fdtab.release (fd);
res = -1;
}
else if ((res = fd) <= 2)
{
off_t res;
- if (dtable.not_open (fd))
+ if (fdtab.not_open (fd))
{
set_errno (EBADF);
res = -1;
}
else
{
- res = dtable[fd]->lseek (pos, dir);
+ res = fdtab[fd]->lseek (pos, dir);
}
syscall_printf ("%d = lseek (%d, %d, %d)", res, fd, pos, dir);
syscall_printf ("close (%d)", fd);
MALLOC_CHECK;
- if (dtable.not_open (fd))
+ if (fdtab.not_open (fd))
{
debug_printf ("handle %d not open", fd);
set_errno (EBADF);
else
{
SetResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK," close");
- res = dtable[fd]->close ();
- dtable.release (fd);
+ res = fdtab[fd]->close ();
+ fdtab.release (fd);
ReleaseResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK," close");
}
{
int res;
- if (dtable.not_open (fd))
+ if (fdtab.not_open (fd))
{
syscall_printf ("0 = isatty (%d)", fd);
return 0;
}
- res = dtable[fd]->is_tty ();
+ res = fdtab[fd]->is_tty ();
syscall_printf ("%d = isatty (%d)", res, fd);
return res;
}
int
fchown (int fd, uid_t uid, gid_t gid)
{
- if (dtable.not_open (fd))
+ if (fdtab.not_open (fd))
{
syscall_printf ("-1 = fchown (%d,...)", fd);
set_errno (EBADF);
return -1;
}
- const char *path = dtable[fd]->get_name ();
+ const char *path = fdtab[fd]->get_name ();
if (path == NULL)
{
int
fchmod (int fd, mode_t mode)
{
- if (dtable.not_open (fd))
+ if (fdtab.not_open (fd))
{
syscall_printf ("-1 = fchmod (%d, 0%o)", fd, mode);
set_errno (EBADF);
return -1;
}
- const char *path = dtable[fd]->get_name ();
+ const char *path = fdtab[fd]->get_name ();
if (path == NULL)
{
{
int r;
- if (dtable.not_open (fd))
+ if (fdtab.not_open (fd))
{
syscall_printf ("-1 = fstat (%d, %p)", fd, buf);
set_errno (EBADF);
else
{
memset (buf, 0, sizeof (struct stat));
- r = dtable[fd]->fstat (buf);
+ r = fdtab[fd]->fstat (buf);
syscall_printf ("%d = fstat (%d, %x)", r,fd,buf);
}
int
fsync (int fd)
{
- if (dtable.not_open (fd))
+ if (fdtab.not_open (fd))
{
syscall_printf ("-1 = fsync (%d)", fd);
set_errno (EBADF);
return -1;
}
- HANDLE h = dtable[fd]->get_handle ();
+ HANDLE h = fdtab[fd]->get_handle ();
if (FlushFileBuffers (h) == 0)
{
void
setdtablesize (int size)
{
- if (size > (int)dtable.size)
- dtable.extend (size);
+ if (size > (int)fdtab.size)
+ fdtab.extend (size);
}
extern "C"
int
getdtablesize ()
{
- return dtable.size;
+ return fdtab.size;
}
extern "C"
char *
ttyname (int fd)
{
- if (dtable.not_open (fd) || !dtable[fd]->is_tty ())
+ if (fdtab.not_open (fd) || !fdtab[fd]->is_tty ())
{
return 0;
}
- return (char *)(dtable[fd]->ttyname ());
+ return (char *)(fdtab[fd]->ttyname ());
}
/* Tells stdio if it should do the cr/lf conversion for this file */
return 0; /* we do it for old apps, due to getc/putc macros */
}
- if (dtable.not_open (fd))
+ if (fdtab.not_open (fd))
{
syscall_printf(" _cifs: fd not open\n");
return 0;
}
- fhandler_base *p = dtable[fd];
+ fhandler_base *p = fdtab[fd];
if (p->get_device() != FH_DISK)
{
extern "C" int
getmode (int fd)
{
- if (dtable.not_open (fd))
+ if (fdtab.not_open (fd))
{
set_errno (EBADF);
return -1;
}
- return dtable[fd]->get_flags () & (O_BINARY | O_TEXT);
+ return fdtab[fd]->get_flags () & (O_BINARY | O_TEXT);
}
/* Set a file descriptor into text or binary mode, returning the
extern "C" int
setmode (int fd, int mode)
{
- if (dtable.not_open (fd))
+ if (fdtab.not_open (fd))
{
set_errno (EBADF);
return -1;
return -1;
}
- fhandler_base *p = dtable[fd];
+ fhandler_base *p = fdtab[fd];
/* Note that we have no way to indicate the case that writes are
binary but not reads, or vice-versa. These cases can arise when
{
int res = -1;
- if (dtable.not_open (fd))
+ if (fdtab.not_open (fd))
{
set_errno (EBADF);
}
else
{
- HANDLE h = dtable[fd]->get_handle ();
+ HANDLE h = fdtab[fd]->get_handle ();
off_t prev_loc;
if (h)
{
/* remember curr file pointer location */
- prev_loc = dtable[fd]->lseek (0, SEEK_CUR);
+ prev_loc = fdtab[fd]->lseek (0, SEEK_CUR);
- dtable[fd]->lseek (length, SEEK_SET);
+ fdtab[fd]->lseek (length, SEEK_SET);
if (!SetEndOfFile (h))
{
__seterrno ();
res = 0;
/* restore original file pointer location */
- dtable[fd]->lseek (prev_loc, 0);
+ fdtab[fd]->lseek (prev_loc, 0);
}
}
syscall_printf ("%d = ftruncate (%d, %d)", res, fd, length);
{
long res = -1;
- if (dtable.not_open (fd))
+ if (fdtab.not_open (fd))
{
set_errno ( EBADF);
}
else
{
- res = (long) dtable[fd]->get_handle ();
+ res = (long) fdtab[fd]->get_handle ();
}
syscall_printf ("%d = get_osfhandle(%d)", res, fd);
int
fstatfs (int fd, struct statfs *sfs)
{
- if (dtable.not_open (fd))
+ if (fdtab.not_open (fd))
{
set_errno (EBADF);
return -1;
}
- fhandler_disk_file *f = (fhandler_disk_file *) dtable[fd];
+ fhandler_disk_file *f = (fhandler_disk_file *) fdtab[fd];
return statfs (f->get_name (), sfs);
}
char *
ptsname (int fd)
{
- if (dtable.not_open (fd))
+ if (fdtab.not_open (fd))
{
set_errno (EBADF);
return 0;
}
- return (char *)(dtable[fd]->ptsname ());
+ return (char *)(fdtab[fd]->ptsname ());
}
/* FIXME: what is this? */
return 1048576;
case _SC_OPEN_MAX:
/* FIXME: this returns the current limit which can increase
- if and when hinfo::find_unused_handle is called. Perhaps
+ if and when dtable::find_unused_handle is called. Perhaps
we should return NOFILE or OPEN_MAX instead? */
- return dtable.size;
+ return fdtab.size;
case _SC_PAGESIZE:
{
SYSTEM_INFO b;
interleaved, we must lock the first byte of the file
This works on Win32 even if we created the file above.
*/
- HANDLE fHandle = dtable[fileno (fp)]->get_handle ();
+ HANDLE fHandle = fdtab[fileno (fp)]->get_handle ();
if (LockFile (fHandle, 0, 0, 1, 0) == FALSE)
{
debug_printf ("failed to lock file %s", get_win95_event_log_path());
{
int res = -1;
- if (dtable.not_open (fd))
+ if (fdtab.not_open (fd))
{
set_errno (EBADF);
goto out;
}
fhandler_base *fh;
- fh = dtable[fd];
+ fh = fdtab[fd];
if (!fh->is_tty ())
set_errno (ENOTTY);
termios_printf ("tcdrain");
- if (dtable.not_open (fd))
+ if (fdtab.not_open (fd))
{
set_errno (EBADF);
goto out;
}
fhandler_base *fh;
- fh = dtable[fd];
+ fh = fdtab[fd];
if (!fh->is_tty ())
set_errno (ENOTTY);
{
int res = -1;
- if (dtable.not_open (fd))
+ if (fdtab.not_open (fd))
{
set_errno (EBADF);
goto out;
}
fhandler_base *fh;
- fh = dtable[fd];
+ fh = fdtab[fd];
if (!fh->is_tty ())
set_errno (ENOTTY);
{
int res = -1;
- if (dtable.not_open (fd))
+ if (fdtab.not_open (fd))
{
set_errno (EBADF);
goto out;
}
fhandler_base *fh;
- fh = dtable[fd];
+ fh = fdtab[fd];
if (!fh->is_tty ())
set_errno (ENOTTY);
int res = -1;
t = __tonew_termios (t);
- if (dtable.not_open (fd))
+ if (fdtab.not_open (fd))
{
set_errno (EBADF);
goto out;
}
fhandler_base *fh;
- fh = dtable[fd];
+ fh = fdtab[fd];
if (!fh->is_tty ())
set_errno (ENOTTY);
int res = -1;
struct termios *t = __makenew_termios (in_t);
- if (dtable.not_open (fd))
+ if (fdtab.not_open (fd))
set_errno (EBADF);
- else if (!dtable[fd]->is_tty ())
+ else if (!fdtab[fd]->is_tty ())
set_errno (ENOTTY);
else
{
- if ((res = dtable[fd]->tcgetattr (t)) == 0)
+ if ((res = fdtab[fd]->tcgetattr (t)) == 0)
(void) __toapp_termios (in_t, t);
}
{
int res = -1;
- if (dtable.not_open (fd))
+ if (fdtab.not_open (fd))
set_errno (EBADF);
- else if (!dtable[fd]->is_tty ())
+ else if (!fdtab[fd]->is_tty ())
set_errno (ENOTTY);
else
- res = dtable[fd]->tcgetpgrp ();
+ res = fdtab[fd]->tcgetpgrp ();
termios_printf ("%d = tcgetpgrp (%d)", res, fd);
return res;
{
int res = -1;
- if (dtable.not_open (fd))
+ if (fdtab.not_open (fd))
set_errno (EBADF);
- else if (!dtable[fd]->is_tty ())
+ else if (!fdtab[fd]->is_tty ())
set_errno (ENOTTY);
else
- res = dtable[fd]->tcsetpgrp (pgid);
+ res = fdtab[fd]->tcsetpgrp (pgid);
termios_printf ("%d = tcsetpgrp (%d, %x)", res, fd, pgid);
return res;
void __stdcall
create_tty_master (int ttynum)
{
- tty_master = (fhandler_tty_master *) dtable.build_fhandler (-1, FH_TTYM,
+ tty_master = (fhandler_tty_master *) fdtab.build_fhandler (-1, FH_TTYM,
"/dev/ttym", ttynum);
if (tty_master->init (ttynum))
api_fatal ("Can't create master tty");
Do not change this value. */
#define SIZEOF_PER_PROCESS (42 * 4)
-class hinfo
+class dtable
{
fhandler_base **fds;
fhandler_base **fds_on_hold;
int first_fd_for_open;
public:
size_t size;
- hinfo () {first_fd_for_open = 3;}
+ dtable () {first_fd_for_open = 3;}
int vfork_child_dup ();
void vfork_parent_restore ();
fhandler_base *dup_worker (fhandler_base *oldfh);
void malloc_init (void);
/* fd table */
-void dtable_init (void);
-void hinfo_init (void);
-extern hinfo dtable;
+void fdtab_init (void);
+void stdio_init (void);
+extern dtable fdtab;
/* UID/GID */
void uinfo_init (void);
int _kill (int, int);
int _raise (int sig);
-int getdtablesize ();
-void setdtablesize (int);
+int getfdtabsize ();
+void setfdtabsize (int);
extern DWORD binmode;
extern char _data_start__, _data_end__, _bss_start__, _bss_end__;