ASCII vs BINARY on OS/2 in perlio
authorIlya Zakharevich <ilya@math.berkeley.edu>
Tue, 2 Apr 2002 00:37:08 +0000 (19:37 -0500)
committerJarkko Hietaniemi <jhi@iki.fi>
Tue, 2 Apr 2002 15:05:58 +0000 (15:05 +0000)
Message-ID: <20020402003708.A8648@math.ohio-state.edu>

p4raw-id: //depot/perl@15682

os2/os2ish.h
perlio.c

index d1c45ad..360da42 100644 (file)
@@ -370,6 +370,16 @@ void *emx_realloc (void *, size_t);
         ? (--FILE_ptr(fp), ++FILE_cnt(fp), (int)c) : ungetc(c,fp))
 #endif
 
+#define PERLIO_IS_BINMODE_FD(fd) _PERLIO_IS_BINMODE_FD(fd)
+
+static inline bool
+_PERLIO_IS_BINMODE_FD(int fd)
+{
+    int *pflags = _fd_flags(fd);
+
+    return pflags && (*pflags) & O_BINARY;
+}
+
 /* ctermid is missing from emx0.9d */
 char *ctermid(char *s);
 
index 1253696..0f34462 100644 (file)
--- a/perlio.c
+++ b/perlio.c
@@ -2891,18 +2891,23 @@ PerlIOBuf_open(pTHX_ PerlIO_funcs *self, PerlIO_list_t *layers,
                return NULL;
            } else {
                fd = PerlIO_fileno(f);
-#ifdef PERLIO_USING_CRLF
-               /*
-                * do something about failing setmode()? --jhi
-                */
-               PerlLIO_setmode(fd, O_BINARY);
-#endif
                if (init && fd == 2) {
                    /*
                     * Initial stderr is unbuffered
                     */
                    PerlIOBase(f)->flags |= PERLIO_F_UNBUF;
                }
+#ifdef PERLIO_USING_CRLF
+#  ifdef PERLIO_IS_BINMODE_FD
+               if (PERLIO_IS_BINMODE_FD(fd))
+                   PerlIO_binmode(f,  '<'/*not used*/, O_BINARY, Nullch);
+               else
+#  endif
+               /*
+                * do something about failing setmode()? --jhi
+                */
+               PerlLIO_setmode(fd, O_BINARY);
+#endif
            }
        }
     }