From f3ea62a847c523db2437aee6f17d852e3765bf86 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Tue, 24 Apr 2001 02:07:58 +0000 Subject: [PATCH] Remove trailing underscore from fhandler_base and friends, throughout. * fhandler.h (fhandler_base::set_open_status): New method. Stores original open status. (fhandler_base::get_open_status): New method. Retrieves original open status. (fhandler_base::reset_to_open_binmode): New method. * fhandler.cc (fhandler_base::open): Save open status. (fhandler_base::init): Ditto. * fhandler_clipboard.cc (fhandler_clipboard::open): Ditto. * fhandler_console.cc (fhandler_console::open): Ditto. * fhandler_dsp.cc (fhandler_dsp::open): Ditto. * fhandler_dev_mem.cc (fhandler_dev_mem::open): Ditto. * fhandler_dev_random.cc (fhandler_dev_random::open): Ditto. * fhandler_serial.cc (fhandler_serial::open): Ditto. * fhandler_tty_slave.cc (fhandler_tty_slave::open): Ditto. * fhandler_tty_master.cc (fhandler_tty_master::open): Ditto. * fhandler_dev_zero.cc (fhandler_dev_zero::open): Ditto. * syscalls.cc (setmode): Rework so that 0 mode value causes reversion to open state. * fhandler_tty_slave.cc (fhandler_tty_slave::read): Use correct multiplier when converting from deciseconds to milliseconds. --- winsup/cygwin/ChangeLog | 25 ++++++++++ winsup/cygwin/fhandler.cc | 77 +++++++++++++++-------------- winsup/cygwin/fhandler.h | 35 ++++++++----- winsup/cygwin/fhandler_clipboard.cc | 1 + winsup/cygwin/fhandler_console.cc | 1 + winsup/cygwin/fhandler_dsp.cc | 9 ++-- winsup/cygwin/fhandler_mem.cc | 1 + winsup/cygwin/fhandler_random.cc | 1 + winsup/cygwin/fhandler_serial.cc | 1 + winsup/cygwin/fhandler_tty.cc | 14 ++++-- winsup/cygwin/fhandler_windows.cc | 1 + winsup/cygwin/fhandler_zero.cc | 1 + winsup/cygwin/syscalls.cc | 12 ++--- 13 files changed, 113 insertions(+), 66 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index b0fc4af7d..06c8bd6f8 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,28 @@ +Mon Apr 23 22:00:29 2001 Christopher Faylor + + Remove trailing underscore from fhandler_base and friends, throughout. + * fhandler.h (fhandler_base::set_open_status): New method. Stores + original open status. + (fhandler_base::get_open_status): New method. Retrieves original open + status. + (fhandler_base::reset_to_open_binmode): New method. + * fhandler.cc (fhandler_base::open): Save open status. + (fhandler_base::init): Ditto. + * fhandler_clipboard.cc (fhandler_clipboard::open): Ditto. + * fhandler_console.cc (fhandler_console::open): Ditto. + * fhandler_dsp.cc (fhandler_dsp::open): Ditto. + * fhandler_dev_mem.cc (fhandler_dev_mem::open): Ditto. + * fhandler_dev_random.cc (fhandler_dev_random::open): Ditto. + * fhandler_serial.cc (fhandler_serial::open): Ditto. + * fhandler_tty_slave.cc (fhandler_tty_slave::open): Ditto. + * fhandler_tty_master.cc (fhandler_tty_master::open): Ditto. + * fhandler_dev_zero.cc (fhandler_dev_zero::open): Ditto. + * syscalls.cc (setmode): Rework so that 0 mode value causes reversion + to open state. + + * fhandler_tty_slave.cc (fhandler_tty_slave::read): Use correct + multiplier when converting from deciseconds to milliseconds. + Mon Apr 23 13:28:35 2001 Christopher Faylor * fhandler.h (fhandler_base::clear_r_binary): New method. diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc index 330a7be1c..d94429665 100644 --- a/winsup/cygwin/fhandler.cc +++ b/winsup/cygwin/fhandler.cc @@ -37,8 +37,8 @@ inline fhandler_base& fhandler_base::operator =(fhandler_base &x) { memcpy (this, &x, sizeof *this); - unix_path_name_ = x.unix_path_name_ ? cstrdup (x.unix_path_name_) : NULL; - win32_path_name_ = x.win32_path_name_ ? cstrdup (x.win32_path_name_) : NULL; + unix_path_name = x.unix_path_name ? cstrdup (x.unix_path_name) : NULL; + win32_path_name = x.win32_path_name ? cstrdup (x.win32_path_name) : NULL; rabuf = NULL; ralen = 0; raixget = 0; @@ -154,33 +154,33 @@ fhandler_base::set_name (const char *unix_path, const char *win32_path, int unit { if (!no_free_names ()) { - if (unix_path_name_ != NULL && unix_path_name_ != fhandler_disk_dummy_name) - cfree (unix_path_name_); - if (win32_path_name_ != NULL && unix_path_name_ != fhandler_disk_dummy_name) - cfree (win32_path_name_); + if (unix_path_name != NULL && unix_path_name != fhandler_disk_dummy_name) + cfree (unix_path_name); + if (win32_path_name != NULL && unix_path_name != fhandler_disk_dummy_name) + cfree (win32_path_name); } - unix_path_name_ = win32_path_name_ = NULL; + unix_path_name = win32_path_name = NULL; if (unix_path == NULL || !*unix_path) return; - unix_path_name_ = cstrdup (unix_path); - if (unix_path_name_ == NULL) + unix_path_name = cstrdup (unix_path); + if (unix_path_name == NULL) { system_printf ("fatal error. strdup failed"); exit (ENOMEM); } if (win32_path) - win32_path_name_ = cstrdup (win32_path); + win32_path_name = cstrdup (win32_path); else { const char *fmt = get_native_name (); - win32_path_name_ = (char *) cmalloc (HEAP_STR, strlen(fmt) + 16); - __small_sprintf (win32_path_name_, fmt, unit); + win32_path_name = (char *) cmalloc (HEAP_STR, strlen(fmt) + 16); + __small_sprintf (win32_path_name, fmt, unit); } - if (win32_path_name_ == NULL) + if (win32_path_name == NULL) { system_printf ("fatal error. strdup failed"); exit (ENOMEM); @@ -236,7 +236,7 @@ fhandler_base::raw_read (void *ptr, size_t ulen) if (is_at_eof (get_handle (), errcode)) return 0; default: - syscall_printf ("ReadFile %s failed, %E", unix_path_name_); + syscall_printf ("ReadFile %s failed, %E", unix_path_name); __seterrno_from_win_error (errcode); return -1; break; @@ -310,25 +310,25 @@ fhandler_base::open (int flags, mode_t mode) if (get_device () == FH_TAPE) { - access_ = GENERIC_READ | GENERIC_WRITE; + access = GENERIC_READ | GENERIC_WRITE; } else if ((flags & (O_RDONLY | O_WRONLY | O_RDWR)) == O_RDONLY) { - access_ = GENERIC_READ; + access = GENERIC_READ; } else if ((flags & (O_RDONLY | O_WRONLY | O_RDWR)) == O_WRONLY) { - access_ = GENERIC_WRITE; + access = GENERIC_WRITE; } else { - access_ = GENERIC_READ | GENERIC_WRITE; + access = GENERIC_READ | GENERIC_WRITE; } /* Allow reliable lseek on disk devices. */ if (get_device () == FH_FLOPPY) { - access_ |= GENERIC_READ; + access |= GENERIC_READ; } /* FIXME: O_EXCL handling? */ @@ -366,13 +366,13 @@ fhandler_base::open (int flags, mode_t mode) if (get_device () == FH_SERIAL) file_attributes |= FILE_FLAG_OVERLAPPED; - x = CreateFileA (get_win32_name (), access_, shared, + x = CreateFileA (get_win32_name (), access, shared, &sec_none, creation_distribution, file_attributes, 0); syscall_printf ("%p = CreateFileA (%s, %p, %p, %p, %p, %p, 0)", - x, get_win32_name (), access_, shared, + x, get_win32_name (), access, shared, &sec_none, creation_distribution, file_attributes); @@ -390,7 +390,7 @@ fhandler_base::open (int flags, mode_t mode) && GetLastError () != ERROR_ALREADY_EXISTS) set_file_attribute (has_acls (), get_win32_name (), mode); - namehash_ = hash_path_name (0, get_win32_name ()); + namehash = hash_path_name (0, get_win32_name ()); set_io_handle (x); int bin; int fmode; @@ -425,6 +425,7 @@ fhandler_base::open (int flags, mode_t mode) } res = 1; + set_open_status (); done: syscall_printf ("%d = fhandler_base::open (%s, %p)", res, get_win32_name (), flags); @@ -674,7 +675,7 @@ fhandler_base::lseek (off_t offset, int whence) set_readahead_valid (0); } - debug_printf ("lseek (%s, %d, %d)", unix_path_name_, offset, whence); + debug_printf ("lseek (%s, %d, %d)", unix_path_name, offset, whence); #if 0 /* lseek has no business messing about with text-mode stuff */ @@ -995,7 +996,7 @@ fhandler_base::init (HANDLE f, DWORD a, mode_t bin) set_io_handle (f); set_r_binary (bin); set_w_binary (bin); - access_ = a; + access = a; a &= GENERIC_READ | GENERIC_WRITE; if (a == GENERIC_READ) set_flags (O_RDONLY); @@ -1003,6 +1004,7 @@ fhandler_base::init (HANDLE f, DWORD a, mode_t bin) set_flags (O_WRONLY); if (a == (GENERIC_READ | GENERIC_WRITE)) set_flags (O_RDWR); + set_open_status (); debug_printf ("created new fhandler_base for handle %p", f); } @@ -1149,15 +1151,16 @@ fhandler_base::operator delete (void *p) /* Normal I/O constructor */ fhandler_base::fhandler_base (DWORD devtype, const char *name, int unit): - access_ (0), + access (0), io_handle (NULL), - namehash_ (0), - openflags_ (0), + namehash (0), + openflags (0), rabuf (NULL), ralen (0), raixget (0), raixput (0), - rabuflen (0) + rabuflen (0), + open_status (0) { status = devtype; int bin = __fmode & O_TEXT ? 0 : 1; @@ -1168,7 +1171,7 @@ fhandler_base::fhandler_base (DWORD devtype, const char *name, int unit): if (!get_w_binset ()) set_w_binary (bin); } - unix_path_name_ = win32_path_name_ = NULL; + unix_path_name = win32_path_name = NULL; set_name (name, NULL, unit); } @@ -1177,14 +1180,14 @@ fhandler_base::~fhandler_base (void) { if (!no_free_names ()) { - if (unix_path_name_ != NULL && unix_path_name_ != fhandler_disk_dummy_name) - cfree (unix_path_name_); - if (win32_path_name_ != NULL && win32_path_name_ != fhandler_disk_dummy_name) - cfree (win32_path_name_); + if (unix_path_name != NULL && unix_path_name != fhandler_disk_dummy_name) + cfree (unix_path_name); + if (win32_path_name != NULL && win32_path_name != fhandler_disk_dummy_name) + cfree (win32_path_name); } if (rabuf) free (rabuf); - unix_path_name_ = win32_path_name_ = NULL; + unix_path_name = win32_path_name = NULL; } /**********************************************************************/ @@ -1195,7 +1198,7 @@ fhandler_disk_file::fhandler_disk_file (const char *name) : { set_cb (sizeof *this); set_no_free_names (); - unix_path_name_ = win32_path_name_ = fhandler_disk_dummy_name; + unix_path_name = win32_path_name = fhandler_disk_dummy_name; } int @@ -1227,7 +1230,7 @@ fhandler_disk_file::open (path_conv& real_path, int flags, mode_t mode) { if (get_win32_name () == fhandler_disk_dummy_name) { - win32_path_name_ = real_path.get_win32 (); + win32_path_name = real_path.get_win32 (); set_no_free_names (); } @@ -1255,7 +1258,7 @@ fhandler_disk_file::open (path_conv& real_path, int flags, mode_t mode) which returns a valid handle when trying to open a file in a non existant directory. */ if (real_path.has_buggy_open () - && GetFileAttributes (win32_path_name_) == (DWORD) -1) + && GetFileAttributes (win32_path_name) == (DWORD) -1) { debug_printf ("Buggy open detected."); close (); diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index 6c432f7c9..ac000bac7 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -65,7 +65,7 @@ enum FH_W95LSBUG= 0x00400000, /* set when lseek is called as a flag that * _write should check if we've moved beyond * EOF, zero filling if so. */ - FH_NOFRNAME= 0x00800000, /* Set if shouldn't free unix_path_name_ and + FH_NOFRNAME= 0x00800000, /* Set if shouldn't free unix_path_name and windows_path_name_ on destruction. */ FH_NOEINTR = 0x01000000, /* Set if I/O should be uninterruptible. */ FH_FFIXUP = 0x02000000, /* Set if need to fixup after fork. */ @@ -145,14 +145,14 @@ private: public: int cb; private: - int access_; + int access; HANDLE io_handle; - unsigned long namehash_; /* hashed filename, used as inode num */ + unsigned long namehash; /* hashed filename, used as inode num */ /* Full unix path name of this file */ /* File open flags from open () and fcntl () calls */ - int openflags_; + int openflags; protected: char *rabuf; /* used for crlf conversion in text files */ @@ -161,8 +161,9 @@ protected: size_t raixput; size_t rabuflen; - char *unix_path_name_; - char *win32_path_name_; + char *unix_path_name; + char *win32_path_name; + DWORD open_status; public: void set_name (const char * unix_path, const char * win32_path = NULL, @@ -180,14 +181,14 @@ public: virtual int get_unit () { return 0; } virtual BOOL is_slow () { return get_device () < FH_SLOW; } - int get_access () { return access_; } - void set_access (int x) { access_ = x; } + int get_access () { return access; } + void set_access (int x) { access = x; } int get_async () { return FHISSETF (ASYNC); } void set_async (int x) { FHCONDSETF (x, ASYNC); } - int get_flags () { return openflags_; } - void set_flags (int x) { openflags_ = x; } + int get_flags () { return openflags; } + void set_flags (int x) { openflags = x; } int get_w_binary () { return FHISSETF (WBINARY); } int get_r_binary () { return FHISSETF (RBINARY); } @@ -199,6 +200,14 @@ public: void set_r_binary (int b) { FHCONDSETF (b, RBINARY); FHSETF (RBINSET); } void clear_w_binary () {FHCLEARF (WBINARY); FHCLEARF (WBINSET); } void clear_r_binary () {FHCLEARF (RBINARY); FHCLEARF (RBINSET); } + void set_open_status () {open_status = status;} + DWORD get_open_status () {return open_status;} + void reset_to_open_binmode () + { + status = status & ~(FH_WBINARY | FH_WBINSET | FH_RBINARY | FH_RBINSET); + status = status | ((FH_WBINARY | FH_WBINSET | FH_RBINARY | FH_RBINSET) + & open_status); + } int get_default_fmode (int flags); @@ -259,9 +268,9 @@ public: void set_no_free_names (int val) { FHCONDSETF (val, NOFRNAME); } void set_no_free_names () { FHSETF (NOFRNAME); } - const char *get_name () { return unix_path_name_; } - const char *get_win32_name () { return win32_path_name_; } - unsigned long get_namehash () { return namehash_; } + const char *get_name () { return unix_path_name; } + const char *get_win32_name () { return win32_path_name; } + unsigned long get_namehash () { return namehash; } virtual void hclose (HANDLE h) {CloseHandle (h);} virtual void set_inheritance (HANDLE &h, int not_inheriting, diff --git a/winsup/cygwin/fhandler_clipboard.cc b/winsup/cygwin/fhandler_clipboard.cc index 20700379f..381f25066 100644 --- a/winsup/cygwin/fhandler_clipboard.cc +++ b/winsup/cygwin/fhandler_clipboard.cc @@ -76,6 +76,7 @@ fhandler_dev_clipboard::open (const char *, int flags, mode_t) membuffer = NULL; if (!cygnativeformat) cygnativeformat = RegisterClipboardFormat (CYGWIN_NATIVE); + set_open_status (); return 1; } diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc index 166c12af0..7a340fe0d 100644 --- a/winsup/cygwin/fhandler_console.cc +++ b/winsup/cygwin/fhandler_console.cc @@ -562,6 +562,7 @@ fhandler_console::open (const char *, int flags, mode_t) TTYCLEARF (RSTCONS); set_ctty (TTY_CONSOLE, flags); + set_open_status (); debug_printf ("opened conin$ %p, conout$ %p", get_io_handle (), get_output_handle ()); diff --git a/winsup/cygwin/fhandler_dsp.cc b/winsup/cygwin/fhandler_dsp.cc index 88cdd30b7..c3d6a67df 100644 --- a/winsup/cygwin/fhandler_dsp.cc +++ b/winsup/cygwin/fhandler_dsp.cc @@ -432,10 +432,13 @@ fhandler_dev_dsp::open (const char *path, int flags, mode_t mode = 0) audiochannels_ = 1; } - if (s_audio.open(audiofreq_, audiobits_, audiochannels_)) - debug_printf("/dev/dsp: successfully opened\n"); - else + if (!s_audio.open(audiofreq_, audiobits_, audiochannels_)) debug_printf("/dev/dsp: failed to open\n"); + else + { + set_open_status (); + debug_printf("/dev/dsp: successfully opened\n"); + } return 1; } diff --git a/winsup/cygwin/fhandler_mem.cc b/winsup/cygwin/fhandler_mem.cc index 2073a6e23..78faf4e0b 100644 --- a/winsup/cygwin/fhandler_mem.cc +++ b/winsup/cygwin/fhandler_mem.cc @@ -125,6 +125,7 @@ fhandler_dev_mem::open (const char *, int flags, mode_t) } set_io_handle (mem); + set_open_status (); return 1; } diff --git a/winsup/cygwin/fhandler_random.cc b/winsup/cygwin/fhandler_random.cc index 3a2811214..b6b8a3ade 100644 --- a/winsup/cygwin/fhandler_random.cc +++ b/winsup/cygwin/fhandler_random.cc @@ -34,6 +34,7 @@ int fhandler_dev_random::open (const char *, int flags, mode_t) { set_flags (flags); + set_open_status (); return 1; } diff --git a/winsup/cygwin/fhandler_serial.cc b/winsup/cygwin/fhandler_serial.cc index fcf47719c..2b517c733 100644 --- a/winsup/cygwin/fhandler_serial.cc +++ b/winsup/cygwin/fhandler_serial.cc @@ -277,6 +277,7 @@ fhandler_serial::open (const char *name, int flags, mode_t mode) } SetCommMask (get_handle (), EV_RXCHAR); + set_open_status (); syscall_printf ("%p = fhandler_serial::open (%s, %p, %p)", res, get_name (), flags, mode); return res; diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index 0aaf1b978..e33d1d31b 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -420,10 +420,10 @@ fhandler_tty_slave::fhandler_tty_slave (int num, const char *name) : ttynum = num; /* FIXME: This is wasteful. We should rewrite the set_name path to eliminate the need for double allocates. */ - unix_path_name_ = (char *) crealloc (unix_path_name_, strlen (win32_path_name_) + 1); - strcpy (unix_path_name_, win32_path_name_); - unix_path_name_[0] = unix_path_name_[4] = '/'; - debug_printf ("unix '%s', win32 '%s'", unix_path_name_, win32_path_name_); + unix_path_name = (char *) crealloc (unix_path_name, strlen (win32_path_name) + 1); + strcpy (unix_path_name, win32_path_name); + unix_path_name[0] = unix_path_name[4] = '/'; + debug_printf ("unix '%s', win32 '%s'", unix_path_name, win32_path_name); inuse = NULL; } @@ -434,6 +434,8 @@ fhandler_tty_slave::fhandler_tty_slave (const char *name) : inuse = NULL; } +/* FIXME: This function needs to close handles when it has + a failing condition. */ int fhandler_tty_slave::open (const char *, int flags, mode_t) { @@ -531,6 +533,7 @@ fhandler_tty_slave::open (const char *, int flags, mode_t) ProtectHandle1 (nh, to_pty); CloseHandle (tty_owner); + set_open_status (); termios_printf ("tty%d opened", ttynum); return 1; @@ -632,7 +635,7 @@ fhandler_tty_slave::read (void *ptr, size_t len) if (vmin == 0) time_to_wait = INFINITE; else - time_to_wait = (vtime == 0 ? INFINITE : 10 * vtime); + time_to_wait = (vtime == 0 ? INFINITE : 100 * vtime); } else time_to_wait = INFINITE; @@ -951,6 +954,7 @@ fhandler_pty_master::open (const char *, int flags, mode_t) cygwin_shared->tty[ttynum]->common_init (this); inuse = get_ttyp ()->create_inuse (TTY_MASTER_ALIVE, FALSE); set_flags (flags); + set_open_status (); termios_printf ("opened pty master tty%d<%p>", ttynum, this); return 1; diff --git a/winsup/cygwin/fhandler_windows.cc b/winsup/cygwin/fhandler_windows.cc index f937d81c4..c5f5e0763 100644 --- a/winsup/cygwin/fhandler_windows.cc +++ b/winsup/cygwin/fhandler_windows.cc @@ -58,6 +58,7 @@ fhandler_windows::open (const char *, int flags, mode_t) { set_flags (flags); set_close_on_exec_flag (1); + set_open_status (); return 1; } diff --git a/winsup/cygwin/fhandler_zero.cc b/winsup/cygwin/fhandler_zero.cc index 4c74abc07..bef73f0fc 100644 --- a/winsup/cygwin/fhandler_zero.cc +++ b/winsup/cygwin/fhandler_zero.cc @@ -24,6 +24,7 @@ int fhandler_dev_zero::open (const char *, int flags, mode_t) { set_flags (flags); + set_open_status (); return 1; } diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index 3211ab934..191b3a91c 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -1651,21 +1651,18 @@ setmode (int fd, int mode) else res = 0; - if (mode & O_BINARY) + if (!mode) + p->reset_to_open_binmode (); + else if (mode & O_BINARY) { p->set_w_binary (1); p->set_r_binary (1); } - else if (mode & O_TEXT) + else { p->set_w_binary (0); p->set_r_binary (0); } - else - { - p->clear_w_binary (); - p->clear_r_binary (); - } if (_cygwin_istext_for_stdio (fd)) setmode_mode = O_TEXT; @@ -1677,7 +1674,6 @@ setmode (int fd, int mode) syscall_printf ("setmode (%d<%s>, %s) returns %s\n", fd, p->get_name (), mode & O_TEXT ? "text" : "binary", res & O_TEXT ? "text" : "binary"); - return res; }