Fix up mix of man(7)/mdoc(7).
[netbsd-mini2440.git] / regress / lib / libc / gen / seekdir-twice / seekdir-twice.c
blob16a6c1ca3f792298fd8b98073c63a6e826c9e811
1 #include <assert.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <dirent.h>
5 #include <sys/stat.h>
7 int
8 main(void)
10 DIR *dp;
12 mkdir("t", 0755);
13 creat("t/a", 0600);
14 creat("t/b", 0600);
15 creat("t/c", 0600);
17 if (dp = opendir("t")) {
18 char *wasname;
19 struct dirent *entry;
20 long here;
22 /* skip two */
23 entry = readdir(dp);
24 entry = readdir(dp);
25 entry = readdir(dp);
26 #ifdef DEBUG
27 printf("first found: %s\n", entry->d_name);
28 #endif
30 here = telldir(dp);
31 #ifdef DEBUG
32 printf("pos returned by telldir: %d\n", here);
33 #endif
34 entry = readdir(dp);
35 #ifdef DEBUG
36 printf("second found: %s\n", entry->d_name);
37 #endif
39 wasname = strdup(entry->d_name);
40 entry = readdir(dp);
41 #ifdef DEBUG
42 printf("third found: %s\n", entry->d_name);
43 #endif
45 seekdir(dp, here);
46 entry = readdir(dp);
47 #ifdef DEBUG
48 printf("should be == second: %s\n", entry->d_name);
50 printf("pos given to seekdir: %d\n", here);
51 #else
52 assert(strcmp(entry->d_name, wasname) == 0);
53 #endif
54 seekdir(dp, here);
55 here = telldir(dp);
56 #ifdef DEBUG
57 printf("pos returned by telldir: %d\n", here);
58 #endif
60 entry = readdir(dp);
61 #ifdef DEBUG
62 printf("should be == second: %s\n", entry->d_name);
63 #else
64 assert(strcmp(entry->d_name, wasname) == 0);
65 #endif
67 seekdir(dp, here);
68 entry = readdir(dp);
69 #ifdef DEBUG
70 printf("should be == second: %s\n", entry->d_name);
71 #else
72 assert(strcmp(entry->d_name, wasname) == 0);
73 #endif
75 closedir(dp);
77 return 0;