From e940ddbba91304b2a80fdaa904f5b12c22b13e0a Mon Sep 17 00:00:00 2001 From: Nicholas Clark Date: Thu, 23 Aug 2001 00:29:06 +0100 Subject: [PATCH] (was Re: PerlIO regerssion tests?) Message-Id: <20010822232906.Z82818@plum.flirble.org> p4raw-id: //depot/perl@11747 --- perlio.c | 5 ++++- pod/perlfunc.pod | 5 ++--- t/io/binmode.t | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 t/io/binmode.t diff --git a/perlio.c b/perlio.c index e1730c8..90867de 100644 --- a/perlio.c +++ b/perlio.c @@ -1968,7 +1968,10 @@ PerlIOUnix_pushed(PerlIO *f, const char *mode, SV *arg) { PerlIOUnix *s = PerlIOSelf(f,PerlIOUnix); s->fd = PerlIO_fileno(PerlIONext(f)); - s->oflags = PerlIOUnix_oflags(mode); + /* XXX could (or should) we retrieve the oflags from the open file handle + rather than believing the "mode" we are passed in? + XXX Should the value on NULL mode be 0 or -1? */ + s->oflags = mode ? PerlIOUnix_oflags(mode) : -1; } PerlIOBase(f)->flags |= PERLIO_F_OPEN; return code; diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index b4c3711..951fada 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -450,13 +450,12 @@ on systems where the run-time libraries distinguish between binary and text files. If FILEHANDLE is an expression, the value is taken as the name of the filehandle. DISCIPLINE can be either of C<":raw"> for binary mode or C<":crlf"> for "text" mode. If the DISCIPLINE is -omitted, it defaults to C<":raw">. +omitted, it defaults to C<":raw">. Returns true on success, C on +failure. binmode() should be called after open() but before any I/O is done on the filehandle. -On many systems binmode() currently has no effect, but in future, it -will be extended to support user-defined input and output disciplines. On some systems binmode() is necessary when you're not working with a text file. For the sake of portability it is a good idea to always use it when appropriate, and to never use it when it isn't appropriate. diff --git a/t/io/binmode.t b/t/io/binmode.t new file mode 100644 index 0000000..76fd5a7 --- /dev/null +++ b/t/io/binmode.t @@ -0,0 +1,20 @@ +#!./perl -w + +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; +} + + +use Test::More tests => 8; + +ok( binmode(STDERR), 'STDERR made binary' ); +ok( binmode(STDERR, ":unix"), ' with unix discipline' ); +ok( binmode(STDERR, ":raw"), ' raw' ); +ok( binmode(STDERR, ":crlf"), ' and crlf' ); + +# If this one fails, we're in trouble. So we just bail out. +ok( binmode(STDOUT), 'STDOUT made binary' ) || exit(1); +ok( binmode(STDOUT, ":unix"), ' with unix discipline' ); +ok( binmode(STDERR, ":raw"), ' raw' ); +ok( binmode(STDERR, ":crlf"), ' and crlf' ); -- 2.7.4