Last change
on this file was 2036, checked in by bird, 20 years ago |
Initial revision
|
-
Property cvs2svn:cvs-rev
set to
1.1
-
Property svn:eol-style
set to
native
-
Property svn:executable
set to
*
-
Property svn:keywords
set to
Author Date Id Revision
|
File size:
688 bytes
|
Line | |
---|
1 | #include <dirent.h>
|
---|
2 | #include <errno.h>
|
---|
3 | #include <errno.h>
|
---|
4 | #include <stdio.h>
|
---|
5 | #include <stdlib.h>
|
---|
6 | #include <unistd.h>
|
---|
7 | #include <sys/types.h>
|
---|
8 |
|
---|
9 |
|
---|
10 | int
|
---|
11 | main (void)
|
---|
12 | {
|
---|
13 | DIR *dirp;
|
---|
14 | struct dirent* ent;
|
---|
15 |
|
---|
16 | /* open a dir stream */
|
---|
17 | dirp = opendir ("/tmp");
|
---|
18 | if (dirp == NULL)
|
---|
19 | {
|
---|
20 | if (errno == ENOENT)
|
---|
21 | exit (0);
|
---|
22 |
|
---|
23 | perror ("opendir");
|
---|
24 | exit (1);
|
---|
25 | }
|
---|
26 |
|
---|
27 | /* close the directory file descriptor, making it invalid */
|
---|
28 | if (close (dirfd (dirp)) != 0)
|
---|
29 | {
|
---|
30 | puts ("could not close directory file descriptor");
|
---|
31 | /* This is not an error. It is not guaranteed this is possible. */
|
---|
32 | return 0;
|
---|
33 | }
|
---|
34 |
|
---|
35 | ent = readdir (dirp);
|
---|
36 |
|
---|
37 | return ent != NULL || errno != EBADF;
|
---|
38 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.