OSDN Git Service

* syscalls.cc (setsid): Detach process from its console if the current
[pf3gnuchains/sourceware.git] / winsup / cygwin / dtable.h
1 /* dtable.h: fd table definition.
2
3    Copyright 2000, 2001 Red Hat, Inc.
4
5 This file is part of Cygwin.
6
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
9 details. */
10
11 /* Initial and increment values for cygwin's fd table */
12 #define NOFILE_INCR    32
13
14 #include "thread.h"
15
16 class dtable
17 {
18   fhandler_base **fds;
19   fhandler_base **fds_on_hold;
20   int first_fd_for_open;
21   int cnt_need_fixup_before;
22   int console_fds;
23 public:
24   size_t size;
25
26   dtable () : first_fd_for_open(3), cnt_need_fixup_before(0), console_fds(0) {}
27   void init () {first_fd_for_open = 3;}
28
29   void dec_need_fixup_before ()
30     { if (cnt_need_fixup_before > 0) --cnt_need_fixup_before; }
31   void inc_need_fixup_before ()
32     { cnt_need_fixup_before++; }
33   BOOL need_fixup_before ()
34     { return cnt_need_fixup_before > 0; }
35
36   void dec_console_fds ();
37   void inc_console_fds ()
38     { console_fds++; }
39   BOOL has_console_fds ()
40     { return console_fds > 0; }
41
42   int vfork_child_dup ();
43   void vfork_parent_restore ();
44   void vfork_child_fixup ();
45   fhandler_base *dup_worker (fhandler_base *oldfh);
46   int extend (int howmuch);
47   void fixup_before_exec (DWORD win_proc_id);
48   void fixup_before_fork (DWORD win_proc_id);
49   void fixup_after_fork (HANDLE);
50   fhandler_base *build_fhandler (int fd, DWORD dev, const char *name,
51                                  int unit = -1);
52   fhandler_base *build_fhandler (int fd, const char *name, HANDLE h);
53   int not_open (int fd)
54   {
55     SetResourceLock (LOCK_FD_LIST, READ_LOCK, "not_open");
56
57     int res = fd < 0 || fd >= (int) size || fds[fd] == NULL;
58
59     ReleaseResourceLock (LOCK_FD_LIST, READ_LOCK, "not open");
60     return res;
61   }
62   int find_unused_handle (int start);
63   int find_unused_handle () { return find_unused_handle (first_fd_for_open);}
64   void release (int fd);
65   void init_std_file_from_handle (int fd, HANDLE handle, DWORD access, const char *name);
66   int dup2 (int oldfd, int newfd);
67   void fixup_after_exec (HANDLE);
68   inline fhandler_base *operator [](int fd) { return fds[fd]; }
69   select_record *select_read (int fd, select_record *s);
70   select_record *select_write (int fd, select_record *s);
71   select_record *select_except (int fd, select_record *s);
72   operator fhandler_base **() {return fds;}
73 };
74
75 void dtable_init (void);
76 void stdio_init (void);
77 extern dtable fdtab;
78
79 extern "C" int getfdtabsize ();
80 extern "C" void setfdtabsize (int);