diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 1836ff8e6..c9ae24341 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,52 @@ +2002-06-04 Christopher Faylor + + Remove fcntl.h includes throughout. + * fhandler.h: Move fcntl.h include here. + (fhandler_base::set_flags): Accept supplied_bin argument. Make + non-inlined. + * dtable.cc (dtable::init_std_file_from_handle): Just use binmode from + pc. + (reset_to_open_binmode): Use set_flags. + * cygwin.din (open): Avoid newlib wrapper. + (read): Ditto. + (unlink): Ditto. + (write): Ditto. + * fhandler.cc (fhandler_base::set_flags): Accept supplied_bin argument. + Make binmode decisions here. + (fhandler_base::open): Avoid using pc if it is NULL. Eliminate binmode + logic. Just call set_flags with binmode argument. + (fhandler_base::init): Call set_flags with binmode argument. + * fhandler_clipboard.cc (fhandler_dev_clipboard::open): Ditto. + * fhandler_console.cc (fhandler_console::open): Ditto. + (fhandler_console::init): Force binary on open. + * fhandler_disk_file.cc (fhandler_disk_file::open): Don't set binmode + here. Let it happen in base class. + * fhandler_dsp.cc (fhandler_dev_dsp::open): Force binmode open. Set + return value appropriately if unable to open. + * fhandler_proc.cc (fhandler_proc::open): Make sure flags are set + before open_status. + * fhandler_process.cc (fhandler_process::open): Ditto. + * fhandler_registry.cc (fhandler_registry::open): Ditto. + * fhandler_random.cc (fhandler_dev_random::fhandler_dev_random): Ditto. + * fhandler_raw.cc (fhandler_dev_raw::open): Force O_BINARY by default. + * fhandler_serial.cc (fhandler_serial::init): Ditto. + * fhandler_tty.cc (fhandler_tty_slave::open): Ditto. + (fhandler_pty_master::open): Ditto. + * fhandler_virtual.cc (fhandler_virtual::open): Ditto. + * fhandler_windows.cc (fhandler_windows::open): Ditto. + * fhandler_zero.cc (fhandler_dev_zero::open): Ditto. + * net.cc (fdsock): Ditto. + * path.cc (path_conv::check): Avoid checking for executable extension + when directory. (Suggested by Pavel Tsekov) + (set_flags): Set PATH_TEXT explicitly, when appropriate. + (mount_info::conv_to_win32_path): Use set_flags() to set path flags. + * path.h (PATH_TEXT): New enum. + (path_conv::binmode): Return appropriate constant based on binmode. + * pipe.cc (make_pipe): Set binmode to O_TEXT xor O_BINARY. + * syscalls.cc (setmode_helper): Make debugging message a little + clearer. + (setmode): Set binmode via set_flags. + 2002-06-04 Corinna Vinschen * fhandler.h (class fhandler_socket): Add private method @@ -69,14 +118,14 @@ (create_token): Delete logonserver and call to get_logon_server. Adjust arguments of get_group_sidlist, see above. * security.h: Delete declaration of get_logon_server_and_user_domain - and add declaration of get_logon_server. + and add declaration of get_logon_server. * uinfo.cc (internal_get_login): Call get_logon_server instead of get_logon_server_and_user_domain. 2002-06-02 Christopher Faylor - * dtable.cc (handle_to_fn): Use largest match for device. Correctly - (?) deal with remote drive weirdness. + * dtable.cc (handle_to_fn): Use largest match for device. Correctly + (?) deal with remote drive weirdness. 2002-06-02 Christopher Faylor diff --git a/winsup/cygwin/cygwin.din b/winsup/cygwin/cygwin.din index ccea8797c..709b311e0 100644 --- a/winsup/cygwin/cygwin.din +++ b/winsup/cygwin/cygwin.din @@ -575,8 +575,8 @@ nextafter _nextafter = nextafter nextafterf _nextafterf = nextafterf -open -_open = open +_open +open = _open opendir _opendir = opendir pathconf @@ -610,8 +610,8 @@ _rand = rand random initstate setstate -read -_read = read +_read +read = read readdir _readdir = readdir readlink @@ -896,8 +896,8 @@ uname _uname = uname ungetc _ungetc = ungetc -unlink -_unlink = unlink +_unlink +unlink = _unlink usleep _usleep = usleep utime @@ -940,8 +940,8 @@ wcstombs _wcstombs = wcstombs wctomb _wctomb = wctomb -write -_write = write +_write +write = _write barfly = write writev _writev = writev diff --git a/winsup/cygwin/dir.cc b/winsup/cygwin/dir.cc index 7de99329f..c9509b65a 100644 --- a/winsup/cygwin/dir.cc +++ b/winsup/cygwin/dir.cc @@ -9,7 +9,6 @@ Cygwin license. Please consult the file "CYGWIN_LICENSE" for details. */ #include "winsup.h" -#include #include #include #include diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc index 06f48c49f..6c532bc12 100644 --- a/winsup/cygwin/dtable.cc +++ b/winsup/cygwin/dtable.cc @@ -16,7 +16,6 @@ details. */ #include #include #include -#include #include #include #include @@ -216,7 +215,6 @@ cygwin_attach_handle_to_fd (char *name, int fd, HANDLE handle, mode_t bin, void dtable::init_std_file_from_handle (int fd, HANDLE handle, DWORD myaccess) { - int bin = -1; const char *name; CONSOLE_SCREEN_BUFFER_INFO buf; struct sockaddr sa; @@ -234,20 +232,13 @@ dtable::init_std_file_from_handle (int fd, HANDLE handle, DWORD myaccess) name = NULL; else { - if (__fmode) - bin = __fmode; - else - bin = (int) binmode ?: -1; - - /* See if we can consoleify it - if it is a console, - don't open it in binary. That will screw up our crlfs*/ + /* See if we can consoleify it */ if (GetConsoleScreenBufferInfo (handle, &buf)) { if (ISSTATE (myself, PID_USETTY)) name = "/dev/tty"; else name = "/dev/conout"; - bin = 0; } else if (GetNumberOfConsoleInputEvents (handle, (DWORD *) &buf)) { @@ -255,7 +246,6 @@ dtable::init_std_file_from_handle (int fd, HANDLE handle, DWORD myaccess) name = "/dev/tty"; else name = "/dev/conin"; - bin = 0; } else if (ft == FILE_TYPE_PIPE) { @@ -263,8 +253,6 @@ dtable::init_std_file_from_handle (int fd, HANDLE handle, DWORD myaccess) name = "/dev/piper"; else name = "/dev/pipew"; - if (bin == 0) - bin = O_BINARY; } else if (wsock_started && getpeername ((SOCKET) handle, &sa, &sal) == 0) name = "/dev/socket"; @@ -280,7 +268,7 @@ dtable::init_std_file_from_handle (int fd, HANDLE handle, DWORD myaccess) { path_conv pc; build_fhandler_from_name (fd, name, handle, pc)->init (handle, myaccess, - bin < 0 ? pc.isbinary () : bin); + pc.binmode ()); set_std_handle (fd); paranoid_printf ("fd %d, handle %p", fd, handle); } diff --git a/winsup/cygwin/environ.cc b/winsup/cygwin/environ.cc index f07dd4a42..16922e2e5 100644 --- a/winsup/cygwin/environ.cc +++ b/winsup/cygwin/environ.cc @@ -12,7 +12,6 @@ details. */ #include #include #include -#include #include #include #include "pinfo.h" diff --git a/winsup/cygwin/fcntl.cc b/winsup/cygwin/fcntl.cc index 95b622c04..f0479e6b8 100644 --- a/winsup/cygwin/fcntl.cc +++ b/winsup/cygwin/fcntl.cc @@ -9,7 +9,6 @@ Cygwin license. Please consult the file "CYGWIN_LICENSE" for details. */ #include "winsup.h" -#include #include #include #include diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc index 820096bcc..67fe64f53 100644 --- a/winsup/cygwin/fhandler.cc +++ b/winsup/cygwin/fhandler.cc @@ -9,7 +9,6 @@ Cygwin license. Please consult the file "CYGWIN_LICENSE" for details. */ #include "winsup.h" -#include #include #include #include @@ -58,6 +57,33 @@ fhandler_base::puts_readahead (const char *s, size_t len) return success; } +void +fhandler_base::set_flags (int flags, int supplied_bin) +{ + int bin; + int fmode; + debug_printf ("flags %p, supplied_bin %p", flags, supplied_bin); + if ((bin = flags & (O_BINARY | O_TEXT))) + debug_printf ("O_TEXT/O_BINARY set in flags %p", bin); + else if (get_r_binset () && get_w_binset ()) + bin = get_r_binary () ? O_BINARY : O_TEXT; // FIXME: Not quite right + else if (supplied_bin) + bin = supplied_bin; + else if ((fmode = get_default_fmode (flags)) & O_BINARY) + bin = O_BINARY; + else if (fmode & O_TEXT) + bin = O_TEXT; + else + bin = get_w_binary () || get_r_binary () || (binmode != O_TEXT) ? + O_BINARY : O_TEXT; + + openflags = flags | bin; + + set_r_binary (bin & O_BINARY); + set_w_binary (bin & O_BINARY); + syscall_printf ("filemode set to %s", bin ? "binary" : "text"); +} + int fhandler_base::put_readahead (char value) { @@ -381,10 +407,8 @@ fhandler_base::open (path_conv *pc, int flags, mode_t mode) /* CreateFile() with dwDesiredAccess == 0 when called on remote share returns some handle, even if file doesn't exist. This code works around this bug. */ - if (get_query_open () && - isremote () && - creation_distribution == OPEN_EXISTING && - !pc->exists ()) + if (get_query_open () && isremote () && + creation_distribution == OPEN_EXISTING && pc && !pc->exists ()) { set_errno (ENOENT); goto done; @@ -424,30 +448,7 @@ fhandler_base::open (path_conv *pc, int flags, mode_t mode) set_file_attribute (has_acls (), get_win32_name (), mode); set_io_handle (x); - if (get_w_binset () && get_r_binset ()) - syscall_printf ("filemode already set to %d/%d", get_r_binary (), get_w_binary ()); - else - { - int bin; - int fmode; - if ((bin = flags & (O_BINARY | O_TEXT))) - /* nothing to do */; - else if ((fmode = get_default_fmode (flags)) & O_BINARY) - bin = O_BINARY; - else if (fmode & O_TEXT) - bin = O_TEXT; - else - bin = get_w_binary () || get_r_binary () || (binmode != O_TEXT); - - if (bin & O_TEXT) - bin = 0; - - set_flags (flags | (bin ? O_BINARY : O_TEXT)); - - set_r_binary (bin); - set_w_binary (bin); - syscall_printf ("filemode set to %s", bin ? "binary" : "text"); - } + set_flags (flags, pc ? pc->binmode () : 0); res = 1; set_open_status (); @@ -849,18 +850,16 @@ void fhandler_base::init (HANDLE f, DWORD a, mode_t bin) { set_io_handle (f); - set_r_binary (bin); - set_w_binary (bin); access = a; a &= GENERIC_READ | GENERIC_WRITE; - int oflags = 0; + int flags = 0; if (a == GENERIC_READ) - oflags = O_RDONLY; + flags = O_RDONLY; else if (a == GENERIC_WRITE) - oflags = O_WRONLY; + flags = O_WRONLY; else if (a == (GENERIC_READ | GENERIC_WRITE)) - oflags = O_RDWR; - set_flags (oflags | (bin ? O_BINARY : O_TEXT)); + flags = O_RDWR; + set_flags (flags, bin); set_open_status (); debug_printf ("created new fhandler_base for handle %p, bin %d", f, get_r_binary ()); } diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index 3d8d7ef37..28f7082eb 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -12,6 +12,7 @@ details. */ #define _FHANDLER_H_ #include +#include enum { @@ -174,7 +175,7 @@ class fhandler_base void set_async (int x) { FHCONDSETF (x, ASYNC); } int get_flags () { return openflags; } - void set_flags (int x) { openflags = x; } + void set_flags (int x, int supplied_bin = 0); bool is_nonblocking (); void set_nonblocking (int yes); @@ -197,9 +198,9 @@ class fhandler_base 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); + set_flags ((get_flags () & ~(O_TEXT | O_BINARY)) + | ((open_status & (FH_WBINARY | FH_RBINARY) + ? O_BINARY : O_TEXT))); } int get_default_fmode (int flags); diff --git a/winsup/cygwin/fhandler_clipboard.cc b/winsup/cygwin/fhandler_clipboard.cc index 266114fe3..e3b26c9fa 100644 --- a/winsup/cygwin/fhandler_clipboard.cc +++ b/winsup/cygwin/fhandler_clipboard.cc @@ -65,7 +65,7 @@ fhandler_dev_clipboard::dup (fhandler_base * child) int fhandler_dev_clipboard::open (path_conv *, int flags, mode_t) { - set_flags (flags); + set_flags (flags, O_TEXT); eof = false; pos = 0; if (membuffer) diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc index 64959e9ee..f7d1f37cf 100644 --- a/winsup/cygwin/fhandler_console.cc +++ b/winsup/cygwin/fhandler_console.cc @@ -12,7 +12,6 @@ details. */ #include #include #include -#include #include #include #include @@ -547,9 +546,7 @@ fhandler_console::open (path_conv *, int flags, mode_t) set_io_handle (INVALID_HANDLE_VALUE); set_output_handle (INVALID_HANDLE_VALUE); - set_flags (flags); - set_w_binary (1); - set_r_binary (1); + set_flags (flags & ~O_TEXT, O_BINARY); /* Open the input handle as handle_ */ h = CreateFileA ("CONIN$", GENERIC_READ|GENERIC_WRITE, @@ -1700,19 +1697,18 @@ get_nonascii_key (INPUT_RECORD& input_rec, char *tmp) void fhandler_console::init (HANDLE f, DWORD a, mode_t bin) { - this->fhandler_termios::init (f, a, bin); - + // this->fhandler_termios::init (f, mode, bin); /* Ensure both input and output console handles are open */ - int mode = 0; + int flags = 0; a &= GENERIC_READ | GENERIC_WRITE; if (a == GENERIC_READ) - mode = O_RDONLY; + flags = O_RDONLY; if (a == GENERIC_WRITE) - mode = O_WRONLY; + flags = O_WRONLY; if (a == (GENERIC_READ | GENERIC_WRITE)) - mode = O_RDWR; - open ((path_conv *) NULL, mode); + flags = O_RDWR; + open ((path_conv *) NULL, flags | O_BINARY); if (f != INVALID_HANDLE_VALUE) CloseHandle (f); /* Reopened by open */ diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc index 167edf469..4d06a410b 100644 --- a/winsup/cygwin/fhandler_disk_file.cc +++ b/winsup/cygwin/fhandler_disk_file.cc @@ -9,7 +9,6 @@ Cygwin license. Please consult the file "CYGWIN_LICENSE" for details. */ #include "winsup.h" -#include #include #include #include @@ -339,9 +338,6 @@ fhandler_disk_file::open (path_conv *real_path, int flags, mode_t mode) return 0; } - set_r_binary (real_path->isbinary ()); - set_w_binary (real_path->isbinary ()); - set_has_acls (real_path->has_acls ()); set_isremote (real_path->isremote ()); diff --git a/winsup/cygwin/fhandler_dsp.cc b/winsup/cygwin/fhandler_dsp.cc index 907eb24e8..f809b93cc 100644 --- a/winsup/cygwin/fhandler_dsp.cc +++ b/winsup/cygwin/fhandler_dsp.cc @@ -15,7 +15,6 @@ details. */ #include #include #include -#include #include #include "cygerrno.h" #include "security.h" @@ -439,7 +438,7 @@ fhandler_dev_dsp::open (path_conv *, int flags, mode_t mode) return 0; } - set_flags (flags); + set_flags (flags & ~O_TEXT, O_BINARY); if (!s_audio) s_audio = new (audio_buf) Audio; @@ -451,14 +450,17 @@ fhandler_dev_dsp::open (path_conv *, int flags, mode_t mode) audiobits_ = 8; audiochannels_ = 1; + int res; if (!s_audio->open (audiofreq_, audiobits_, audiochannels_)) - debug_printf ("/dev/dsp: failed to open\n"); + res = 0; else { set_open_status (); - debug_printf ("/dev/dsp: successfully opened\n"); + res = 1; } - return 1; + + debug_printf ("returns %d", res); + return res; } int diff --git a/winsup/cygwin/fhandler_floppy.cc b/winsup/cygwin/fhandler_floppy.cc index 43daf9d99..3804fdf74 100644 --- a/winsup/cygwin/fhandler_floppy.cc +++ b/winsup/cygwin/fhandler_floppy.cc @@ -11,7 +11,6 @@ details. */ #include "winsup.h" #include -#include #include #include #include diff --git a/winsup/cygwin/fhandler_mem.cc b/winsup/cygwin/fhandler_mem.cc index e5b99526e..9a53b1a22 100644 --- a/winsup/cygwin/fhandler_mem.cc +++ b/winsup/cygwin/fhandler_mem.cc @@ -9,7 +9,6 @@ details. */ #include "winsup.h" -#include #include #include #include diff --git a/winsup/cygwin/fhandler_proc.cc b/winsup/cygwin/fhandler_proc.cc index d9fe8a69f..65accd2e1 100644 --- a/winsup/cygwin/fhandler_proc.cc +++ b/winsup/cygwin/fhandler_proc.cc @@ -9,7 +9,6 @@ Cygwin license. Please consult the file "CYGWIN_LICENSE" for details. */ #include "winsup.h" -#include #include #include #include @@ -301,8 +300,8 @@ fhandler_proc::open (path_conv *pc, int flags, mode_t mode) success: res = 1; + set_flags (flags & ~O_TEXT, O_BINARY); set_open_status (); - set_flags (flags); out: syscall_printf ("%d = fhandler_proc::open (%p, %d)", res, flags, mode); return res; diff --git a/winsup/cygwin/fhandler_process.cc b/winsup/cygwin/fhandler_process.cc index e918c3e4c..fca9fd37b 100644 --- a/winsup/cygwin/fhandler_process.cc +++ b/winsup/cygwin/fhandler_process.cc @@ -9,7 +9,6 @@ Cygwin license. Please consult the file "CYGWIN_LICENSE" for details. */ #include "winsup.h" -#include #include #include #include @@ -237,8 +236,8 @@ fhandler_process::open (path_conv *pc, int flags, mode_t mode) success: res = 1; + set_flags (flags & ~O_TEXT, O_BINARY); set_open_status (); - set_flags (flags); out: syscall_printf ("%d = fhandler_proc::open (%p, %d)", res, flags, mode); return res; diff --git a/winsup/cygwin/fhandler_random.cc b/winsup/cygwin/fhandler_random.cc index 33ccaddea..42481d6eb 100644 --- a/winsup/cygwin/fhandler_random.cc +++ b/winsup/cygwin/fhandler_random.cc @@ -31,7 +31,7 @@ fhandler_dev_random::fhandler_dev_random (int nunit) int fhandler_dev_random::open (path_conv *, int flags, mode_t) { - set_flags (flags); + set_flags (flags & ~O_TEXT, O_BINARY); set_open_status (); return 1; } diff --git a/winsup/cygwin/fhandler_raw.cc b/winsup/cygwin/fhandler_raw.cc index 9486bf563..8ad822c99 100644 --- a/winsup/cygwin/fhandler_raw.cc +++ b/winsup/cygwin/fhandler_raw.cc @@ -10,7 +10,6 @@ #include "winsup.h" #include -#include #include #include @@ -176,9 +175,7 @@ fhandler_dev_raw::open (path_conv *real_path, int flags, mode_t) } set_io_handle (h); - set_flags (flags); - set_r_binary (O_BINARY); - set_w_binary (O_BINARY); + set_flags (flags & ~O_TEXT, O_BINARY); if (devbufsiz > 1L) devbuf = new char [devbufsiz]; diff --git a/winsup/cygwin/fhandler_registry.cc b/winsup/cygwin/fhandler_registry.cc index b4f0eeb59..94220c62a 100644 --- a/winsup/cygwin/fhandler_registry.cc +++ b/winsup/cygwin/fhandler_registry.cc @@ -11,7 +11,6 @@ details. */ /* FIXME: Access permissions are ignored at the moment. */ #include "winsup.h" -#include #include #include #include @@ -481,8 +480,8 @@ fhandler_registry::open (path_conv *pc, int flags, mode_t mode) success: res = 1; + set_flags (flags & ~O_TEXT, O_BINARY); set_open_status (); - set_flags (flags); out: if (hKey != (HKEY) INVALID_HANDLE_VALUE) RegCloseKey (hKey); diff --git a/winsup/cygwin/fhandler_serial.cc b/winsup/cygwin/fhandler_serial.cc index 7d64f1efc..81077b359 100644 --- a/winsup/cygwin/fhandler_serial.cc +++ b/winsup/cygwin/fhandler_serial.cc @@ -9,7 +9,6 @@ Cygwin license. Please consult the file "CYGWIN_LICENSE" for details. */ #include "winsup.h" -#include #include #include #include @@ -201,8 +200,7 @@ fhandler_serial::dump (void) void fhandler_serial::init (HANDLE f, DWORD flags, mode_t bin) { - fhandler_base::init (f, flags, bin); - (void) open (NULL, flags, bin ? O_BINARY : 0); + (void) open (NULL, flags, bin & (O_BINARY | O_TEXT)); } int diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc index 0f1f90bb7..bed274bab 100644 --- a/winsup/cygwin/fhandler_socket.cc +++ b/winsup/cygwin/fhandler_socket.cc @@ -19,7 +19,6 @@ #include #include -#include #define USE_SYS_TYPES_FD_SET #include #include "cygerrno.h" diff --git a/winsup/cygwin/fhandler_tape.cc b/winsup/cygwin/fhandler_tape.cc index a7a3bbe91..aaf1ed751 100644 --- a/winsup/cygwin/fhandler_tape.cc +++ b/winsup/cygwin/fhandler_tape.cc @@ -11,7 +11,6 @@ details. */ #include "winsup.h" #include -#include #include #include #include diff --git a/winsup/cygwin/fhandler_termios.cc b/winsup/cygwin/fhandler_termios.cc index 2f2aa260d..b3cd73561 100644 --- a/winsup/cygwin/fhandler_termios.cc +++ b/winsup/cygwin/fhandler_termios.cc @@ -11,7 +11,6 @@ details. */ #include "winsup.h" #include #include -#include #include #include #include diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index 6668ceffa..03af0e712 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -10,7 +10,6 @@ details. */ #include "winsup.h" #include -#include #include #include #include @@ -455,7 +454,7 @@ fhandler_tty_slave::open (path_conv *, int flags, mode_t) attach_tty (ttynum); tc->set_ctty (ttynum, flags); - set_flags (flags); + set_flags (flags & ~O_TEXT, O_BINARY); /* Create synchronisation events */ char buf[40]; @@ -1007,7 +1006,7 @@ fhandler_pty_master::open (path_conv *, int flags, mode_t) cygwin_shared->tty[ttynum]->common_init (this); inuse = get_ttyp ()->create_inuse (TTY_MASTER_ALIVE); - set_flags (flags); + set_flags (flags & ~O_TEXT, O_BINARY); set_open_status (); termios_printf ("opened pty master tty%d<%p>", ttynum, this); diff --git a/winsup/cygwin/fhandler_virtual.cc b/winsup/cygwin/fhandler_virtual.cc index 500bfb3eb..a05543426 100644 --- a/winsup/cygwin/fhandler_virtual.cc +++ b/winsup/cygwin/fhandler_virtual.cc @@ -9,7 +9,6 @@ Cygwin license. Please consult the file "CYGWIN_LICENSE" for details. */ #include "winsup.h" -#include #include #include #include @@ -208,7 +207,7 @@ fhandler_virtual::open (path_conv *, int flags, mode_t mode) set_execable_p (not_executable); set_socket_p (false); - set_flags (flags); + set_flags (flags & ~O_TEXT, O_BINARY); set_nohandle (true); diff --git a/winsup/cygwin/fhandler_windows.cc b/winsup/cygwin/fhandler_windows.cc index 861ddefa1..ddff3f9cb 100644 --- a/winsup/cygwin/fhandler_windows.cc +++ b/winsup/cygwin/fhandler_windows.cc @@ -54,7 +54,7 @@ fhandler_windows::fhandler_windows () int fhandler_windows::open (path_conv *, int flags, mode_t) { - set_flags (flags); + set_flags (flags & ~O_TEXT, O_BINARY); 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 50b34abab..ff8271344 100644 --- a/winsup/cygwin/fhandler_zero.cc +++ b/winsup/cygwin/fhandler_zero.cc @@ -23,7 +23,7 @@ fhandler_dev_zero::fhandler_dev_zero () int fhandler_dev_zero::open (path_conv *, int flags, mode_t) { - set_flags (flags); + set_flags (flags & ~O_TEXT, O_BINARY); set_open_status (); return 1; } diff --git a/winsup/cygwin/fork.cc b/winsup/cygwin/fork.cc index c204fdd51..2bb8eb5ce 100644 --- a/winsup/cygwin/fork.cc +++ b/winsup/cygwin/fork.cc @@ -12,7 +12,6 @@ details. */ #include #include #include -#include #include #include #include "security.h" diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index 79c65563e..5e1fc8f60 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -21,7 +21,6 @@ details. */ #include #include #include -#include #define USE_SYS_TYPES_FD_SET #include #include "cygerrno.h" @@ -506,7 +505,7 @@ fdsock (int& fd, const char *name, SOCKET soc) debug_printf ("not setting socket inheritance since winsock2_active %d", winsock2_active); fhandler_socket *fh = (fhandler_socket *) cygheap->fdtab.build_fhandler (fd, FH_SOCKET, name); fh->set_io_handle ((HANDLE) soc); - fh->set_flags (O_RDWR); + fh->set_flags (O_RDWR, O_BINARY); debug_printf ("fd %d, name '%s', soc %p", fd, name, soc); return fh; } diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index e6a948382..3d3079774 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -52,7 +52,6 @@ details. */ #include #include #include -#include #include #include #include @@ -803,7 +802,7 @@ out: if (saw_symlinks) set_has_symlinks (); - if (!error && !(path_flags & PATH_ALL_EXEC)) + if (!error && !isdir () && !(path_flags & PATH_ALL_EXEC)) { const char *p = strchr (path, '\0') - 4; if (p >= path && @@ -1342,6 +1341,14 @@ mount_info::init () from_registry (); } +static void +set_flags (unsigned *flags, unsigned val) +{ + *flags = val; + if (!(*flags & PATH_BINARY)) + *flags = PATH_TEXT; +} + /* conv_to_win32_path: Ensure src_path is a pure Win32 path and store the result in win32_path. @@ -1404,7 +1411,7 @@ mount_info::conv_to_win32_path (const char *src_path, char *dst, return rc; } - *flags = set_flags_from_win32_path (dst); + set_flags (flags, (unsigned) set_flags_from_win32_path (dst)); goto out; } @@ -1433,7 +1440,6 @@ mount_info::conv_to_win32_path (const char *src_path, char *dst, if (rc) { debug_printf ("%d = conv_to_win32_path (%s)", rc, src_path); - *flags = 0; return rc; } } @@ -1468,7 +1474,7 @@ mount_info::conv_to_win32_path (const char *src_path, char *dst, } else if (cygdrive_win32_path (pathbuf, dst, unit)) { - *flags = cygdrive_flags; + set_flags (flags, (unsigned) cygdrive_flags); goto out; } else if (mount_table->cygdrive_len > 1) @@ -1506,10 +1512,7 @@ mount_info::conv_to_win32_path (const char *src_path, char *dst, } if (i >= nmounts) - { - backslashify (pathbuf, dst, 0); /* just convert */ - *flags = PATH_BINARY; /* Default to binmode */ - } + backslashify (pathbuf, dst, 0); /* just convert */ else { int n; @@ -1538,7 +1541,7 @@ mount_info::conv_to_win32_path (const char *src_path, char *dst, dst[n++] = '\\'; strcpy (dst + n, p); backslashify (dst, dst, 0); - *flags = mi->flags; + set_flags (flags, (unsigned) mi->flags); } if (!isvirtual_dev (devn)) diff --git a/winsup/cygwin/path.h b/winsup/cygwin/path.h index eefd73fca..50c5a743c 100644 --- a/winsup/cygwin/path.h +++ b/winsup/cygwin/path.h @@ -47,6 +47,7 @@ enum path_types PATH_NOTEXEC = MOUNT_NOTEXEC, PATH_CYGWIN_EXEC = MOUNT_CYGWIN_EXEC, PATH_ALL_EXEC = (PATH_CYGWIN_EXEC | PATH_EXEC), + PATH_TEXT = 0x02000000, PATH_ISDISK = 0x04000000, PATH_HAS_SYMLINKS = 0x10000000, PATH_HASBUGGYOPEN = 0x20000000, @@ -88,7 +89,14 @@ class path_conv int has_symlinks () const {return path_flags & PATH_HAS_SYMLINKS;} int hasgood_inode () const {return path_flags & PATH_HASACLS;} // Not strictly correct int has_buggy_open () const {return path_flags & PATH_HASBUGGYOPEN;} - int isbinary () const {return path_flags & PATH_BINARY;} + int binmode () const + { + if (path_flags & PATH_BINARY) + return O_BINARY; + if (path_flags & PATH_TEXT) + return O_TEXT; + return 0; + } int issymlink () const {return path_flags & PATH_SYMLINK;} int issocket () const {return path_flags & PATH_SOCKET;} int iscygexec () const {return path_flags & PATH_CYGWIN_EXEC;} diff --git a/winsup/cygwin/pipe.cc b/winsup/cygwin/pipe.cc index 5056219ac..9313f085c 100644 --- a/winsup/cygwin/pipe.cc +++ b/winsup/cygwin/pipe.cc @@ -10,7 +10,6 @@ details. */ #include "winsup.h" #include -#include #include #include "cygerrno.h" #include "security.h" @@ -148,7 +147,7 @@ make_pipe (int fildes[2], unsigned int psize, int mode) fhandler_pipe *fhr = (fhandler_pipe *) cygheap->fdtab.build_fhandler (fdr, FH_PIPER, "/dev/piper"); fhandler_pipe *fhw = (fhandler_pipe *) cygheap->fdtab.build_fhandler (fdw, FH_PIPEW, "/dev/pipew"); - int binmode = mode & O_TEXT ? 0 : 1; + int binmode = mode & O_TEXT ?: O_BINARY; fhr->init (r, GENERIC_READ, binmode); fhw->init (w, GENERIC_WRITE, binmode); if (mode & O_NOINHERIT) diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index 0c003dba6..9e28d104e 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -11,7 +11,6 @@ details. */ #include "winsup.h" #include #include /* needed for statfs */ -#include #include #include #include @@ -1624,8 +1623,8 @@ setmode_helper (FILE *f) if (fileno (f) != setmode_file) return 0; syscall_printf ("setmode: file was %s now %s\n", - f->_flags & __SCLE ? "cle" : "raw", - setmode_mode & O_TEXT ? "cle" : "raw"); + f->_flags & __SCLE ? "text" : "raw", + setmode_mode & O_TEXT ? "text" : "raw"); if (setmode_mode & O_TEXT) f->_flags |= __SCLE; else @@ -1673,16 +1672,8 @@ setmode (int fd, int mode) if (!mode) cfd->reset_to_open_binmode (); - else if (mode & O_BINARY) - { - cfd->set_w_binary (1); - cfd->set_r_binary (1); - } else - { - cfd->set_w_binary (0); - cfd->set_r_binary (0); - } + cfd->set_flags ((cfd->get_flags () & ~(O_TEXT | O_BINARY)) | mode); if (_cygwin_istext_for_stdio (fd)) setmode_mode = O_TEXT; @@ -1691,9 +1682,8 @@ setmode (int fd, int mode) setmode_file = fd; _fwalk (_REENT, setmode_helper); - syscall_printf ("setmode (%d<%s>, %s) returns %s\n", fd, cfd->get_name (), - mode & O_TEXT ? "text" : "binary", - res & O_TEXT ? "text" : "binary"); + syscall_printf ("setmode (%d<%s>, %p) returns %s\n", fd, cfd->get_name (), + mode, res & O_TEXT ? "text" : "binary"); return res; }