diff options
author | DJ Delorie <dj@redhat.com> | 2000-05-23 23:52:50 +0000 |
---|---|---|
committer | DJ Delorie <dj@redhat.com> | 2000-05-23 23:52:50 +0000 |
commit | 56cd25ee025db97fd3ba7052e07ec64ab2c3aae3 (patch) | |
tree | 0b22df89e1fa3b22533c54de5d6415c94b1e2a1c /winsup/cygwin/syscalls.cc | |
parent | c4e1aa01152f5b0b9637b965604273a52f040323 (diff) | |
download | newlib-56cd25ee025db97fd3ba7052e07ec64ab2c3aae3.zip newlib-56cd25ee025db97fd3ba7052e07ec64ab2c3aae3.tar.gz newlib-56cd25ee025db97fd3ba7052e07ec64ab2c3aae3.tar.bz2 |
* syscalls.cc (_cygwin_istext_for_stdio): New, for newlib
* include/cygwin/version.h: Bump API number for detect old
programs using old getc/putc macros
Diffstat (limited to 'winsup/cygwin/syscalls.cc')
-rw-r--r-- | winsup/cygwin/syscalls.cc | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index e6a5c06..cf743d0 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -1431,6 +1431,42 @@ ttyname (int fd) return (char *)(dtable[fd]->ttyname ()); } +/* Tells stdio if it should do the cr/lf conversion for this file */ +extern "C" int _cygwin_istext_for_stdio (int fd); +int +_cygwin_istext_for_stdio (int fd) +{ + syscall_printf("_cygwin_istext_for_stdio (%d)\n", fd); + if (CYGWIN_VERSION_OLD_STDIO_CRLF_HANDLING) + { + syscall_printf(" _cifs: old API\n"); + return 0; /* we do it for old apps, due to getc/putc macros */ + } + + if (dtable.not_open (fd)) + { + syscall_printf(" _cifs: fd not open\n"); + return 0; + } + + fhandler_base *p = dtable[fd]; + + if (p->get_device() != FH_DISK) + { + syscall_printf(" _cifs: fd not disk file\n"); + return 0; + } + + if (p->get_w_binary () || p->get_r_binary ()) + { + syscall_printf(" _cifs: get_*_binary\n"); + return 0; + } + + syscall_printf("_cygwin_istext_for_stdio says yes\n"); + return 1; +} + /* internal newlib function */ extern "C" int _fwalk (struct _reent *ptr, int (*function)(FILE *)); @@ -1442,6 +1478,9 @@ 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"); if (setmode_mode & O_TEXT) f->_flags |= __SCLE; else @@ -1491,10 +1530,17 @@ setmode (int fd, int mode) p->set_r_binary (0); } - setmode_mode = mode; + if (_cygwin_istext_for_stdio (fd)) + setmode_mode = O_TEXT; + else + setmode_mode = O_BINARY; setmode_file = fd; _fwalk(_REENT, setmode_helper); + syscall_printf ("setmode (%d, %s) returns %s\n", fd, + mode&O_TEXT ? "text" : "binary", + res&O_TEXT ? "text" : "binary"); + return res; } |