OSDN Git Service

* child_info.h (CURR_CHILD_INFO_MAGIC): Reset.
[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 suffix_info;
17 class dtable
18 {
19   fhandler_base **fds;
20   fhandler_base **fds_on_hold;
21   int first_fd_for_open;
22   int cnt_need_fixup_before;
23   int console_fds;
24 public:
25   size_t size;
26
27   dtable () : first_fd_for_open(3), cnt_need_fixup_before(0), console_fds(0) {}
28   void init () {first_fd_for_open = 3;}
29
30   void dec_need_fixup_before ()
31     { if (cnt_need_fixup_before > 0) --cnt_need_fixup_before; }
32   void inc_need_fixup_before ()
33     { cnt_need_fixup_before++; }
34   BOOL need_fixup_before ()
35     { return cnt_need_fixup_before > 0; }
36
37   void dec_console_fds ();
38   void inc_console_fds ()
39     { console_fds++; }
40   BOOL has_console_fds ()
41     { return console_fds > 0; }
42
43   int vfork_child_dup ();
44   void vfork_parent_restore ();
45   void vfork_child_fixup ();
46   fhandler_base *dup_worker (fhandler_base *oldfh);
47   int extend (int howmuch);
48   void fixup_before_exec (DWORD win_proc_id);
49   void fixup_before_fork (DWORD win_proc_id);
50   void fixup_after_fork (HANDLE);
51   fhandler_base *build_fhandler (int fd, DWORD dev, const char *unix_name,
52                                  const char *win32_name = NULL, int unit = -1);
53   fhandler_base *build_fhandler (int fd, DWORD dev, char *unix_name = NULL,
54                                  const char *win32_name = NULL, int unit = -1);
55   fhandler_base *build_fhandler_from_name (int fd, const char *name, HANDLE h,
56                                            path_conv& pc,
57                                            unsigned opts = PC_SYM_FOLLOW,
58                                            suffix_info *si = NULL);
59   inline int not_open (int fd)
60   {
61     SetResourceLock (LOCK_FD_LIST, READ_LOCK, "not_open");
62
63     int res = fd < 0 || fd >= (int) size || fds[fd] == NULL;
64
65     ReleaseResourceLock (LOCK_FD_LIST, READ_LOCK, "not open");
66     return res;
67   }
68   int find_unused_handle (int start);
69   int find_unused_handle () { return find_unused_handle (first_fd_for_open);}
70   void release (int fd);
71   void init_std_file_from_handle (int fd, HANDLE handle);
72   int dup2 (int oldfd, int newfd);
73   void fixup_after_exec (HANDLE);
74   inline fhandler_base *operator [](int fd) const { return fds[fd]; }
75   select_record *select_read (int fd, select_record *s);
76   select_record *select_write (int fd, select_record *s);
77   select_record *select_except (int fd, select_record *s);
78   operator fhandler_base **() {return fds;}
79   void stdio_init ();
80   void get_debugger_info ();
81 };
82
83 void dtable_init (void);
84 void stdio_init (void);
85 extern dtable fdtab;
86
87 extern "C" int getfdtabsize ();
88 extern "C" void setfdtabsize (int);