Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

How does Perl handle opendir/readdir/closedir internally?

by Cybercosis (Monk)
on Aug 12, 2001 at 12:14 UTC ( #104219=perlquestion: print w/replies, xml ) Need Help??

Cybercosis has asked for the wisdom of the Perl Monks concerning the following question:

First, some Background:
Background: For those of you who've been following perllib's development (which isn't, to my knowledge, many), there hasn't been a release since 2.01, and that was some time ago. This is because I wanted to implement all of the features that scalars have (files, shared memory, semaphores, etc.). Well, that isn't entirely true, but it'll work for the moment. While I have most of the scalar abilities implemented, there's one that has been escaping me. This brings me to The Question:

The Question: How does perl create and use directory handles?
I've hunted through the source, and there's no mention of the DIR structure, or its underlying __dirstream structure, which makes sense, since somebody decided to make them opaque (and with good reason). I can't, however, figure out how perl accomplishes it! So, I leave it to you internals gurus (you're braver people than I, Gunga Dinn!).

~Cybercosis

nemo accipere quod non merere

Edit by tye to update title

  • Comment on How does Perl handle opendir/readdir/closedir internally?

Replies are listed 'Best First'.
Re: How *do* they do that?
by abstracts (Hermit) on Aug 12, 2001 at 13:56 UTC
    Hello

    If you look at the opendir(3) manpage, you will see that perl's opendir, readdir and closedir are handled directly by their C counterparts. The DIR * data type is defined I believe in dirent.h or in sys/types.h.

    I believe implementing opendir, readdir and closedir are straightforward in XS given that this is their calling syntax:

    DIR *opendir(const char *name); int closedir(DIR *dir); struct dirent *readdir(DIR *dir);

    Did I answer the question?

    Aziz,,,

      In an XS program it appears that it is slightly more complicated than this as the XSUB.h for perl 5.72 has :

      # define opendir PerlDir_open

      having previously undefined opendir.

      PerlDir_open itself is defined in iperlsys.h in 5.72 - this is so that it can be made to fit in with the whole PerlIO thing.

      Probably the easiest way of finding out what is going on in here is to look at the implementation of pp_open_dir in pp_sys.c and then work backward from there.

      /J\

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://104219]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2022-11-28 17:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?