problem with scandir

David Marks marks at AIVAX.RADC.AF.MIL
Fri Apr 5 06:19:26 AEST 1991


[ Mail to originator bounced... How can info-iris always get the mail through..]
Mark,
  First, I'm sure its a typo, but the structure name is "dirent" not "direct".
Secondly, you have to provide a place for the directory information to go,
not just a place for a pointer to a pointer of the information.
This should do the trick:

  struct dirent namelist;   /* this is where the info will really go */
                            /* it says to allocate space for a dirent */
  struct dirent *namelist_p; /* this declares space for a ptr to a dirent */
  struct dirent **namelist_p_p; /* and this a ptr to a ptr to a dirent */

/* the relationship amongst these is: */
/*      namelist_p_p  -> namelist_p ->  namelist  */


/* make the declared pointers really point to where we want */
  namelist_p = &namelist; /* point to namelist */
  namelist_p_p = &namelist_p;  /* point to namelist_p */

/* the call would then look like: */
    scandir("/bin", namelist_p_p, NULL, NULL);

OR possibly,

    scandir("/bin", &namelist_p, NULL, NULL);

OR MAYBE, but I don't think so,

    scandir("/bin", &&namelist, NULL, NULL);

--------------------------------------------

I guess you get the idea from the above verbose example.  I got trapped by
this problem several times, and still do now and again.  The trick is
to always know what the pointers are pointing to and that you have
allocated space for the data to actually reside.

I hope this helps.

Dave Marks
Rome Laboratory
marks at aivax.radc.af.mil



More information about the Comp.sys.sgi mailing list