mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-02-06 06:20:23 +08:00
47063f00e4
operators to simplify testing for directory and attributes, throughout. * path.h (path_conv::exists): New method. (path_conv::has_attribute): Ditto. (path_conv::isdir): Ditto. (path_conv::DWORD &): New operator. (path_conv::int &): Ditto. * dir.cc (rmdir): Eliminate a goto. * dtable.cc (dtable::build_fhandler): Accept opt and suffix info for path_conv.check. Return fh == NULL on path_conv error. Pass unit to set_name as appropriate. (dtable::reset_unix_path_name): New method. * dtable.h (dtable): Declare new method. Reflect arg changes to build_fhandler. * fhandler.cc (fhandler_disk_dummy_name): Eliminate. (fhandler_base::set_name): Expect paths to be NULL. Build unix_path_name from win32_path_name when it is a device. (fhandler_base::reset_unix_path_name): New method. (fhandler_base::raw_read): Report EISDIR when ERROR_INVALID_FUNCTION or ERROR_INVALID_PARAMETER and reading a directory. (fhandler_disk_file::fstat): Don't call stat_dev since we should now never be calling fhandler_disk_file methods with devices. (fhandler_base::fhandler_base): Clear {unix,win32}_path_name. (fhandler_base::~fhandler_base): Always free {unix,win32}_path_name. (fhandler_disk_file::fhandler_disk_file): Remove set_no_free_names kludge. (fhandler_disk_file::open): Ditto. * fhandler.h (fhandler_base::no_free_names): Eliminate. (fhandler_base::set_no_free_names): Ditto. * fhandler_tty.cc (fhandler_tty_slave::fhandler_tty_slave): Don't set unix_path_name here. * path.cc (fchdir): Lock fd table throughout. Use new dtable::reset_unix_path_name method to reset path. * syscalls.cc (stat_worker): Reorganize to always call fstat method. Pass path_conv method to fhandler_*::open. (chroot): Elminate a goto.
85 lines
2.5 KiB
C++
85 lines
2.5 KiB
C++
/* dtable.h: fd table definition.
|
|
|
|
Copyright 2000, 2001 Red Hat, Inc.
|
|
|
|
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. */
|
|
|
|
/* Initial and increment values for cygwin's fd table */
|
|
#define NOFILE_INCR 32
|
|
|
|
#include "thread.h"
|
|
|
|
class suffix_info;
|
|
class dtable
|
|
{
|
|
fhandler_base **fds;
|
|
fhandler_base **fds_on_hold;
|
|
int first_fd_for_open;
|
|
int cnt_need_fixup_before;
|
|
int console_fds;
|
|
public:
|
|
size_t size;
|
|
|
|
dtable () : first_fd_for_open(3), cnt_need_fixup_before(0), console_fds(0) {}
|
|
void init () {first_fd_for_open = 3;}
|
|
|
|
void dec_need_fixup_before ()
|
|
{ if (cnt_need_fixup_before > 0) --cnt_need_fixup_before; }
|
|
void inc_need_fixup_before ()
|
|
{ cnt_need_fixup_before++; }
|
|
BOOL need_fixup_before ()
|
|
{ return cnt_need_fixup_before > 0; }
|
|
|
|
void dec_console_fds ();
|
|
void inc_console_fds ()
|
|
{ console_fds++; }
|
|
BOOL has_console_fds ()
|
|
{ return console_fds > 0; }
|
|
|
|
int vfork_child_dup ();
|
|
void vfork_parent_restore ();
|
|
void vfork_child_fixup ();
|
|
fhandler_base *dup_worker (fhandler_base *oldfh);
|
|
int extend (int howmuch);
|
|
void fixup_before_exec (DWORD win_proc_id);
|
|
void fixup_before_fork (DWORD win_proc_id);
|
|
void fixup_after_fork (HANDLE);
|
|
fhandler_base *build_fhandler (int fd, DWORD dev, const char *name,
|
|
int unit = -1);
|
|
fhandler_base *build_fhandler (int fd, const char *name, HANDLE h = NULL,
|
|
path_conv *pc = NULL,
|
|
unsigned opts = PC_SYM_FOLLOW, suffix_info *si = NULL);
|
|
inline int not_open (int fd)
|
|
{
|
|
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;
|
|
}
|
|
void reset_unix_path_name (int fd, const char *name);
|
|
int find_unused_handle (int start);
|
|
int find_unused_handle () { return find_unused_handle (first_fd_for_open);}
|
|
void release (int fd);
|
|
void init_std_file_from_handle (int fd, HANDLE handle, DWORD access, const char *name);
|
|
int dup2 (int oldfd, int newfd);
|
|
void fixup_after_exec (HANDLE);
|
|
inline fhandler_base *operator [](int fd) const { return fds[fd]; }
|
|
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;}
|
|
};
|
|
|
|
void dtable_init (void);
|
|
void stdio_init (void);
|
|
extern dtable fdtab;
|
|
|
|
extern "C" int getfdtabsize ();
|
|
extern "C" void setfdtabsize (int);
|