question about "requiring" linux/

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hello. I am wrapping up a rather large server migration job I was tasked
with. Everything is running wonderfully.

One thing I noticed in a few legacy Perl scripts that had <code>require
"linux/";</code> near the top and making use of functions like
S_ISLNK, resulting in this sort of error, which can be easily

$ perl -e 'require "linux/"; &S_ISLNK'
Undefined subroutine &main::S_ISLNK called at -e line 1.

It seems the problem is coming from line 7 in

if(defined( &__KERNEL__) || !defined( &__GLIBC__) ||
((defined(&__GLIBC__) ? &__GLIBC__ : 0) < 2)) {

Here is what the values for those defines are:

$ perl -e 'require
print "[", &__KERNEL__, "]"'
Undefined subroutine &main::__KERNEL__ called at -e line 1.

$ perl -e 'require
print "[", &__GLIBC__, "]"'

&__KERNEL__ is not defined and &__GLIBC__ is 2

If I comment out line 7 (and it's closing brace) then all the &S_ subs
(ie, S_ISLNK) are found properly, but I don't want to use such a hack, I
would like to fix the problem itself.

Thanks for any help.

Perl Info Below

$ perl -v

This is perl, v5.8.8 built for i686-linux-64int-ld

$ perl -V
Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
    osname=linux, osvers=2.4.20-8, archname=i686-linux-64int-ld
    uname='linux srlinux 2.4.20-8 #1 thu mar 13 17:54:28 est 2003 i686
i686 i386 gnulinux '
    config_args='-Dprefix=/usr/local/perl5.8.8 -Duse64bitint'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=define use64bitall=undef uselongdouble=define
    usemymalloc=n, bincompat5005=undef
    cc='cc', ccflags
='-fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE
    cppflags='-fno-strict-aliasing -pipe -I/usr/local/include
    ccversion='', gccversion='3.2.2 20030222 (Red Hat Linux 3.2.2-5)',
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long long', ivsize=8, nvtype='long double', nvsize=12,
Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Characteristics of this binary (from libperl):
                        USE_LONG_DOUBLE USE_PERLIO
  Built under linux
  Compiled at Feb 11 2008 01:12:44


Re: question about "requiring" linux/

szr wrote:
Quoted text here. Click to load it


require "linux/";


use Fcntl;

perldoc -f stat
[ SNIP ]
         You can import symbolic mode constants ("S_IF*") and functions
         ("S_IS*") from the Fcntl module:

Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

Re: question about "requiring" linux/

John W. Krahn wrote:
Quoted text here. Click to load it


use Fcntl ':mode';

did the trick :)


Re: question about "requiring" linux/

Quoted text here. Click to load it

You should be importing these constants from Fcntl with non-ancient
versions of Perl. h2ph can't always cope with the complicated
conditional definitions in Linux' system headers, so sometimes the
generated .ph files are not useable.

    perl -MFcntl=:mode -le'print S_ISLNK(S_IFLNK)'

Generally speaking you can just use -l instead, though.


Re: question about "requiring" linux/

Ben Morrow wrote:
Quoted text here. Click to load it

Thank you for the information.


Site Timeline