Path: utzoo!attcan!uunet!seismo!sundc!pitstop!sun!oliveb!ames!scubed!warner From: warner@scubed.UUCP (Ken Warner) Newsgroups: comp.unix.wizards Subject: Re: scandir() Keywords: scandir catch-22 Message-ID: <801@scubed.UUCP> Date: 1 Jul 88 14:57:12 GMT References: <1445@uokmax.UUCP> <799@scubed.UUCP> <12267@mimsy.UUCP> Reply-To: warner@scubed.UUCP (Ken Warner) Organization: /etc/organization Lines: 36 In article <12267@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: >In article <799@scubed.UUCP> warner@scubed.UUCP (Ken Warner) writes: >>specific. The trick to using scandir() is to know how many entries are >>in the directory before you make the call to scandir(). >This is wrong (as was the code that called scandir). If you had to >know the directory length first, scandir would be useless. The manual >entry for scandir is correct but misleading (there is no array in >its declaration!). [stuff deleted] > struct direct **list; > int i, n; > /* important: & */ > n = scandir("foo", &list, (int (*)())NULL, (int (*)())NULL); > /* important: & */ > * The type of the second argument to scandir is `pointer to pointer > * to pointer to struct direct', or `struct direct ***'. As a parameter > * this may (but never should) be written as `struct direct *(*namelist[])'. > * The manual is misleading; namelist is neither an array nor a pointer to ^^^^^^^^^^^^^^^^^^^^ You got that right. Sorry for my assertion that you needed to know how many entries were in the directory etc. I took the man page literally. SYNTAX #include #include scandir(dirname, namelist, select, compar) char *dirname; struct direct *(*namelist[]); int (*select)(); int (*compar)(); The only way I could make this declaration work was to declare a static array. And now I don't know why it worked at all. Must have been tired or stupid. My apologies to all. Ken Warner