develooper Front page | perl.perl5.porters | Postings from March 2003

[perl #21672] IO::New and undefined filename behaviour

Thread Next
From:
perlbug-followup
Date:
March 25, 2003 07:50
Subject:
[perl #21672] IO::New and undefined filename behaviour
Message ID:
rt-21672-54038.2.07650993465862@bugs6.perl.org
# New Ticket Created by  mike@exegenix.com 
# Please include the string:  [perl #21672]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=21672 >



This is a bug report for perl from mike@exegenix.com,
generated with the help of perlbug 1.34 running under perl v5.8.0.


-----------------------------------------------------------------
[Please enter your report here]
A colleague wrote some code which was effectively did:

  use FileHandle;
  my $var = undef;
  my $fh = FileHandle->new($var, 'r') or die "...($!) \n";

  while (<$fh>) {
    # ...
  }

and was surprised that using undef or '' for a filename in the 2 arg form 
of FileHandle->new didn't cause an error.

This seems to be because IO::File.pm's open spots that the empty file name isn't
absolute in the case there are 2 or more arguments, and calls sysopen on './'
This succeeds in opening the directory, but the read in the while loop
properly fails setting errno to EISDIR.

I would expect both of the opens below to behave in the same way:

#!/usr/bin/env perl

use strict;
use warnings;

use FileHandle;

my $fh = FileHandle->new('', 'r') or print "2 arg failed\n";
$fh = FileHandle->new('<')        or print "1 arg failed\n";

(currently only 1 arg failed is printed)

Should the empty/undefined filename be checked for in IO::File.pm's open or
is there a better way of viewing this?

Mike

*** IO/File.pm.dist	Wed Mar 19 16:04:58 2003
--- IO/File.pm	Wed Mar 19 16:07:29 2003
***************
*** 158,164 ****
  	    defined $perms or $perms = 0666;
  	    return sysopen($fh, $file, $mode, $perms);
  	}
! 	if (! File::Spec->file_name_is_absolute($file)) {
              $file = File::Spec->catfile(File::Spec->curdir(),$file);
          }
  	$file = IO::Handle::_open_mode_string($mode) . " $file\0";
--- 158,164 ----
  	    defined $perms or $perms = 0666;
  	    return sysopen($fh, $file, $mode, $perms);
  	}
! 	if (defined($file) && length($file) && ! File::Spec->file_name_is_absolute($file)) {
              $file = File::Spec->catfile(File::Spec->curdir(),$file);
          }
  	$file = IO::Handle::_open_mode_string($mode) . " $file\0";

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=library
    severity=low
---
Site configuration information for perl v5.8.0:

Configured by bhcompile at Sun Sep  1 23:55:07 EDT 2002.

Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.4.18-11smp, archname=i386-linux-thread-multi
    uname='linux daffy.perf.redhat.com 2.4.18-11smp #1 smp thu aug 15 06:41:59 edt 2002 i686 i686 i386 gnulinux '
    config_args='-des -Doptimize=-O2 -march=i386 -mcpu=i686 -Dmyhostname=localhost -Dperladmin=root@localhost -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dinstallprefix=/usr -Dprefix=/usr -Darchname=i386-linux -Dvendorprefix=/usr -Dsiteprefix=/usr -Duseshrplib -Dusethreads -Duseithreads -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db -Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallusrbinperl -Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less -isr'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
    optimize='-O2 -march=i386 -mcpu=i686',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -I/usr/include/gdbm'
    ccversion='', gccversion='3.2 20020822 (Red Hat Linux Rawhide 3.2-5)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lgdbm -ldb -ldl -lm -lpthread -lc -lcrypt -lutil
    perllibs=-lnsl -ldl -lm -lpthread -lc -lcrypt -lutil
    libc=/lib/libc-2.2.92.so, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.2.92'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic -Wl,-rpath,/usr/lib/perl5/5.8.0/i386-linux-thread-multi/CORE'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    

---
@INC for perl v5.8.0:
    /usr/lib/perl5/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/5.8.0
    /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.0
    /usr/lib/perl5/site_perl
    /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.0
    /usr/lib/perl5/vendor_perl
    .

---
Environment for perl v5.8.0:
    HOME=/home/won/mike
    LANG=en_US
    LANGUAGE (unset)
    LC_ALL=C
    LD_LIBRARY_PATH=/home/won/mike/exclude/local/lib:
    LOGDIR (unset)
    PATH=/home/won/mike/exclude/local/bin:/home/ex/razoradm/Razor/scripts:/test/cod/bin/glinux:/home/ex/razoradm/Razor/bin:/share/bin:/usr/java/java/bin:/usr/local/exegenix/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/ex/razoradm/Razor/bin:/home/ex/razoradm/razor_db/dsip/RAZOR_UNIVERSE/Scripts:/home/ex/razoradm/Razor/scripts:/home/won/mike/bin:/share/bin
    PERL_BADLANG (unset)
    SHELL=/bin/bash


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About