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 extension when error or
directory.
(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.
This commit is contained in:
Christopher Faylor 2002-06-05 01:42:28 +00:00
parent 915d66ce9e
commit e35f391fa5
33 changed files with 157 additions and 146 deletions

View File

@ -1,3 +1,52 @@
2002-06-04 Christopher Faylor <cgf@redhat.com>
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 <corinna@vinschen.de>
* 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 <cgf@redhat.com>
* 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 <cgf@redhat.com>

View File

@ -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

View File

@ -9,7 +9,6 @@ Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#include "winsup.h"
#include <sys/fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>

View File

@ -16,7 +16,6 @@ details. */
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/cygwin.h>
#include <assert.h>
#include <ntdef.h>
@ -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);
}

View File

@ -12,7 +12,6 @@ details. */
#include <stdlib.h>
#include <stddef.h>
#include <ctype.h>
#include <fcntl.h>
#include <sys/cygwin.h>
#include <cygwin/version.h>
#include "pinfo.h"

View File

@ -9,7 +9,6 @@ Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#include "winsup.h"
#include <fcntl.h>
#include <stdarg.h>
#include <errno.h>
#include <unistd.h>

View File

@ -9,7 +9,6 @@ Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#include "winsup.h"
#include <sys/fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
@ -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 ());
}

View File

@ -12,6 +12,7 @@ details. */
#define _FHANDLER_H_
#include <sys/ioctl.h>
#include <fcntl.h>
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);

View File

@ -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)

View File

@ -12,7 +12,6 @@ details. */
#include <sys/termios.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <wingdi.h>
@ -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 */

View File

@ -9,7 +9,6 @@ Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#include "winsup.h"
#include <sys/fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
@ -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 ());

View File

@ -15,7 +15,6 @@ details. */
#include <errno.h>
#include <windows.h>
#include <sys/soundcard.h>
#include <sys/fcntl.h>
#include <mmsystem.h>
#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

View File

@ -11,7 +11,6 @@ details. */
#include "winsup.h"
#include <sys/termios.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <winioctl.h>

View File

@ -9,7 +9,6 @@
details. */
#include "winsup.h"
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <sys/mman.h>

View File

@ -9,7 +9,6 @@ Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#include "winsup.h"
#include <sys/fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
@ -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;

View File

@ -9,7 +9,6 @@ Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#include "winsup.h"
#include <sys/fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
@ -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;

View File

@ -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;
}

View File

@ -10,7 +10,6 @@
#include "winsup.h"
#include <sys/termios.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
@ -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];

View File

@ -11,7 +11,6 @@ details. */
/* FIXME: Access permissions are ignored at the moment. */
#include "winsup.h"
#include <sys/fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
@ -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);

View File

@ -9,7 +9,6 @@ Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#include "winsup.h"
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
@ -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

View File

@ -19,7 +19,6 @@
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#define USE_SYS_TYPES_FD_SET
#include <winsock2.h>
#include "cygerrno.h"

View File

@ -11,7 +11,6 @@ details. */
#include "winsup.h"
#include <sys/termios.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <sys/mtio.h>

View File

@ -11,7 +11,6 @@ details. */
#include "winsup.h"
#include <sys/termios.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <ctype.h>

View File

@ -10,7 +10,6 @@ details. */
#include "winsup.h"
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
@ -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);

View File

@ -9,7 +9,6 @@ Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#include "winsup.h"
#include <sys/fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
@ -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);

View File

@ -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;

View File

@ -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;
}

View File

@ -12,7 +12,6 @@ details. */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <stdarg.h>
#include <errno.h>
#include "security.h"

View File

@ -21,7 +21,6 @@ details. */
#include <stdlib.h>
#include <unistd.h>
#include <netdb.h>
#include <fcntl.h>
#define USE_SYS_TYPES_FD_SET
#include <winsock2.h>
#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;
}

View File

@ -52,7 +52,6 @@ details. */
#include <stdlib.h>
#include <sys/mount.h>
#include <mntent.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <ctype.h>
@ -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))

View File

@ -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;}

View File

@ -10,7 +10,6 @@ details. */
#include "winsup.h"
#include <unistd.h>
#include <sys/fcntl.h>
#include <errno.h>
#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)

View File

@ -11,7 +11,6 @@ details. */
#include "winsup.h"
#include <sys/stat.h>
#include <sys/vfs.h> /* needed for statfs */
#include <fcntl.h>
#include <pwd.h>
#include <grp.h>
#include <stdlib.h>
@ -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;
}