2000-08-12 13:35:42 +08:00
|
|
|
/* dtable.h: fd table definition.
|
|
|
|
|
2001-07-26 08:10:52 +08:00
|
|
|
Copyright 2000, 2001 Red Hat, Inc.
|
2000-08-12 13:35:42 +08:00
|
|
|
|
|
|
|
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. */
|
|
|
|
|
2000-09-08 10:56:55 +08:00
|
|
|
/* Initial and increment values for cygwin's fd table */
|
|
|
|
#define NOFILE_INCR 32
|
|
|
|
|
2001-05-08 23:16:49 +08:00
|
|
|
#include "thread.h"
|
|
|
|
|
2001-10-01 12:10:07 +08:00
|
|
|
class suffix_info;
|
2000-08-12 13:35:42 +08:00
|
|
|
class dtable
|
|
|
|
{
|
|
|
|
fhandler_base **fds;
|
|
|
|
fhandler_base **fds_on_hold;
|
|
|
|
int first_fd_for_open;
|
2000-10-26 18:13:41 +08:00
|
|
|
int cnt_need_fixup_before;
|
2001-07-26 08:10:52 +08:00
|
|
|
int console_fds;
|
2000-08-12 13:35:42 +08:00
|
|
|
public:
|
|
|
|
size_t size;
|
2000-10-26 18:13:41 +08:00
|
|
|
|
2001-07-26 08:10:52 +08:00
|
|
|
dtable () : first_fd_for_open(3), cnt_need_fixup_before(0), console_fds(0) {}
|
2001-04-19 05:10:15 +08:00
|
|
|
void init () {first_fd_for_open = 3;}
|
2000-10-26 18:13:41 +08:00
|
|
|
|
|
|
|
void dec_need_fixup_before ()
|
|
|
|
{ if (cnt_need_fixup_before > 0) --cnt_need_fixup_before; }
|
|
|
|
void inc_need_fixup_before ()
|
2001-07-26 08:10:52 +08:00
|
|
|
{ cnt_need_fixup_before++; }
|
2000-10-26 18:13:41 +08:00
|
|
|
BOOL need_fixup_before ()
|
|
|
|
{ return cnt_need_fixup_before > 0; }
|
|
|
|
|
2001-07-26 08:10:52 +08:00
|
|
|
void dec_console_fds ();
|
|
|
|
void inc_console_fds ()
|
|
|
|
{ console_fds++; }
|
|
|
|
BOOL has_console_fds ()
|
|
|
|
{ return console_fds > 0; }
|
|
|
|
|
2000-08-12 13:35:42 +08:00
|
|
|
int vfork_child_dup ();
|
|
|
|
void vfork_parent_restore ();
|
2001-04-19 05:10:15 +08:00
|
|
|
void vfork_child_fixup ();
|
2000-08-12 13:35:42 +08:00
|
|
|
fhandler_base *dup_worker (fhandler_base *oldfh);
|
|
|
|
int extend (int howmuch);
|
2000-10-26 18:13:41 +08:00
|
|
|
void fixup_before_exec (DWORD win_proc_id);
|
|
|
|
void fixup_before_fork (DWORD win_proc_id);
|
2000-08-12 13:35:42 +08:00
|
|
|
void fixup_after_fork (HANDLE);
|
2002-02-23 03:33:41 +08:00
|
|
|
fhandler_base *build_fhandler (int fd, DWORD dev, const char *unix_name,
|
|
|
|
const char *win32_name = NULL, int unit = -1);
|
2002-05-24 13:44:10 +08:00
|
|
|
fhandler_base *build_fhandler (int fd, DWORD dev, char *unix_name = NULL,
|
|
|
|
const char *win32_name = NULL, int unit = -1);
|
2001-10-03 11:49:26 +08:00
|
|
|
fhandler_base *build_fhandler_from_name (int fd, const char *name, HANDLE h,
|
|
|
|
path_conv& pc,
|
|
|
|
unsigned opts = PC_SYM_FOLLOW,
|
|
|
|
suffix_info *si = NULL);
|
2001-09-17 11:05:05 +08:00
|
|
|
inline int not_open (int fd)
|
2001-05-08 23:16:49 +08:00
|
|
|
{
|
|
|
|
SetResourceLock (LOCK_FD_LIST, READ_LOCK, "not_open");
|
|
|
|
|
|
|
|
int res = fd < 0 || fd >= (int) size || fds[fd] == NULL;
|
|
|
|
|
|
|
|
ReleaseResourceLock (LOCK_FD_LIST, READ_LOCK, "not open");
|
|
|
|
return res;
|
|
|
|
}
|
2000-08-12 13:35:42 +08:00
|
|
|
int find_unused_handle (int start);
|
|
|
|
int find_unused_handle () { return find_unused_handle (first_fd_for_open);}
|
|
|
|
void release (int fd);
|
2002-10-15 04:25:52 +08:00
|
|
|
void init_std_file_from_handle (int fd, HANDLE handle);
|
2000-08-12 13:35:42 +08:00
|
|
|
int dup2 (int oldfd, int newfd);
|
2001-04-19 05:10:15 +08:00
|
|
|
void fixup_after_exec (HANDLE);
|
2001-09-17 11:05:05 +08:00
|
|
|
inline fhandler_base *operator [](int fd) const { return fds[fd]; }
|
2000-08-12 13:35:42 +08:00
|
|
|
select_record *select_read (int fd, select_record *s);
|
|
|
|
select_record *select_write (int fd, select_record *s);
|
|
|
|
select_record *select_except (int fd, select_record *s);
|
|
|
|
operator fhandler_base **() {return fds;}
|
2002-02-23 03:33:41 +08:00
|
|
|
void stdio_init ();
|
|
|
|
void get_debugger_info ();
|
2002-10-18 01:45:09 +08:00
|
|
|
void set_file_pointers_for_exec ();
|
2000-08-12 13:35:42 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void dtable_init (void);
|
|
|
|
void stdio_init (void);
|
|
|
|
extern dtable fdtab;
|
2000-09-08 10:56:55 +08:00
|
|
|
|
|
|
|
extern "C" int getfdtabsize ();
|
|
|
|
extern "C" void setfdtabsize (int);
|