scandir()
Ken Warner
warner at scubed.UUCP
Sat Jul 2 00:57:12 AEST 1988
In article <12267 at mimsy.UUCP> chris at mimsy.UUCP (Chris Torek) writes:
>In article <799 at scubed.UUCP> warner at 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 <sys/types.h>
#include <sys/dir.h>
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
More information about the Comp.unix.wizards
mailing list