summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--os2/os2ish.h10
-rw-r--r--perlio.c17
2 files changed, 21 insertions, 6 deletions
diff --git a/os2/os2ish.h b/os2/os2ish.h
index d1c45ad86a..360da42aef 100644
--- a/os2/os2ish.h
+++ b/os2/os2ish.h
@@ -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);
diff --git a/perlio.c b/perlio.c
index 12536961fb..0f34462c36 100644
--- 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
}
}
}