mirror of
git://sourceware.org/git/glibc.git
synced 2025-04-06 14:10:30 +08:00
New example for scandir function.
This commit is contained in:
parent
fb63ae13d0
commit
77055d99e4
29
manual/examples/dir2.c
Normal file
29
manual/examples/dir2.c
Normal file
@ -0,0 +1,29 @@
|
||||
/*@group*/
|
||||
#include <stdio.h>
|
||||
#include <dirent.h>
|
||||
/*@end group*/
|
||||
|
||||
static int
|
||||
one (struct dirent *unused)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
struct dirent **eps;
|
||||
int n;
|
||||
|
||||
n = scandir ("./", &eps, one, alphasort);
|
||||
if (n >= 0)
|
||||
{
|
||||
int cnt;
|
||||
for (cnt = 0; cnt < n; ++cnt)
|
||||
puts (eps[cnt]->d_name);
|
||||
}
|
||||
else
|
||||
perror ("Couldn't open the directory");
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user