Mailing List Archive

A small bug in POSIX.pm (new FileHandle)
Well, having been bitten by this once too often, I have endevoured to
fix a minor problem in the "new FileHandle" routine. Specificly using a
mode of "r+", or "+r", gets translated to "<", NOT "+<" as desired. Also
looking at the code, it seems that the POSIX module expects the "+"
character in front (i.e. perl convention), while as far as I can tell,
the POSIX spec (which I don't have, so I may be wrong on this bit),
expects the "+" at the end. The appended patch changes one line (to fix
the "+r" bug), and adds one line (to move the trailing "+" to the
front). Hopefully we can get this in the next patch level, and not have
to bother with it again.

sjb.

Here is the patch:
*** POSIX.pm.orig Wed Aug 2 14:32:08 1995
--- POSIX.pm Tue Aug 29 11:17:03 1995
***************
*** 298,306 ****
POSIX::usage "FileHandle->new(filename, posixmode)" if @_ != 3;
local($class,$filename,$mode) = @_;
local($glob) = &POSIX::gensym;
$mode =~ s/a.*/>>/ ||
$mode =~ s/w.*/>/ ||
! ($mode = '<');
open($glob, "$mode $filename") and
bless \$glob;
}
--- 298,307 ----
POSIX::usage "FileHandle->new(filename, posixmode)" if @_ != 3;
local($class,$filename,$mode) = @_;
local($glob) = &POSIX::gensym;
+ $mode =~ s/\+// && $mode =~ s/^/+/;
$mode =~ s/a.*/>>/ ||
$mode =~ s/w.*/>/ ||
! $mode =~ s/r.*/</;
open($glob, "$mode $filename") and
bless \$glob;
}
Re: A small bug in POSIX.pm (new FileHandle) [ In reply to ]
Excerpts from the mail message of S. John Banner:
) [...] Specificly using a
) mode of "r+", or "+r", gets translated to "<", NOT "+<" as desired.
[...]
) + $mode =~ s/\+// && $mode =~ s/^/+/;
) $mode =~ s/a.*/>>/ ||
) $mode =~ s/w.*/>/ ||
) ! $mode =~ s/r.*/</;

I proposed the following fix a while back:

> We also need to fix the long-time bug, changing several copies of:
>
> $mode =~ s/a.*/>>/ ||
> $mode =~ s/w.*/>/ ||
> ($mode = '<');
>
> to something more like:
>
> $mode =~ s#^a(\+?)$#\1>># ||
> $mode =~ s#^w(\+?)$#\1># ||
> $mode =~ s#^r(\+?)$#\1<# ||
> croak qq<Invalid open() mode: "$mode">;
>
> and using
>
> open( $sym, "$mode $filename\0" );
> ^^
> so white space is preserved.
>
> Unless I am mistaken.

I'll have to check my pile of saved patches to see if the
promised POSIX.pm / FileHandle.pm rewrite that I was replying
to ever showed up here.
--
Tye McQueen tye@metronet.com || tye@doober.usu.edu
Nothing is obvious unless you are overlooking something
http://www.metronet.com/~tye/ (scripts, links, nothing fancy)