diff options
Diffstat (limited to '')
| -rw-r--r-- | src/regress/lib/libc/telldir/Makefile | 5 | ||||
| -rw-r--r-- | src/regress/lib/libc/telldir/telldir.c | 106 |
2 files changed, 111 insertions, 0 deletions
diff --git a/src/regress/lib/libc/telldir/Makefile b/src/regress/lib/libc/telldir/Makefile new file mode 100644 index 0000000000..0927779663 --- /dev/null +++ b/src/regress/lib/libc/telldir/Makefile | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2006/03/25 20:27:11 otto Exp $ | ||
| 2 | |||
| 3 | PROG= telldir | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/telldir/telldir.c b/src/regress/lib/libc/telldir/telldir.c new file mode 100644 index 0000000000..e8c8f6745e --- /dev/null +++ b/src/regress/lib/libc/telldir/telldir.c | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | /* $OpenBSD: telldir.c,v 1.1 2006/03/25 20:27:11 otto Exp $ */ | ||
| 2 | |||
| 3 | /* Written by Otto Moerbeek, 2006, Public domain. */ | ||
| 4 | |||
| 5 | #include <sys/types.h> | ||
| 6 | #include <sys/stat.h> | ||
| 7 | #include <dirent.h> | ||
| 8 | #include <err.h> | ||
| 9 | #include <limits.h> | ||
| 10 | #include <fcntl.h> | ||
| 11 | #include <stdio.h> | ||
| 12 | #include <string.h> | ||
| 13 | #include <unistd.h> | ||
| 14 | |||
| 15 | |||
| 16 | #define NFILES 1000 | ||
| 17 | |||
| 18 | void | ||
| 19 | createfiles(void) | ||
| 20 | { | ||
| 21 | int i, fd; | ||
| 22 | char file[PATH_MAX]; | ||
| 23 | |||
| 24 | mkdir("d", 0755); | ||
| 25 | for (i = 0; i < NFILES; i++) { | ||
| 26 | snprintf(file, sizeof file, "d/%d", i); | ||
| 27 | if ((fd = open(file, O_CREAT | O_WRONLY, 0600)) == -1) | ||
| 28 | err(1, "open %s", file); | ||
| 29 | close(fd); | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | void | ||
| 34 | delfiles(void) | ||
| 35 | { | ||
| 36 | DIR *dp; | ||
| 37 | struct dirent *f; | ||
| 38 | char file[PATH_MAX]; | ||
| 39 | |||
| 40 | dp = opendir("d"); | ||
| 41 | if (dp == NULL) | ||
| 42 | err(1, "opendir"); | ||
| 43 | while (f = readdir(dp)) { | ||
| 44 | if (strcmp(f->d_name, ".") == 0 || | ||
| 45 | strcmp(f->d_name, "..") == 0) | ||
| 46 | continue; | ||
| 47 | snprintf(file, sizeof file, "d/%s", f->d_name); | ||
| 48 | if (unlink(file) == -1) | ||
| 49 | err(1, "unlink %s", f->d_name); | ||
| 50 | } | ||
| 51 | closedir(dp); | ||
| 52 | if (rmdir("d") == -1) | ||
| 53 | err(1, "rmdir"); | ||
| 54 | } | ||
| 55 | |||
| 56 | void | ||
| 57 | loop(DIR *dp, int i) | ||
| 58 | { | ||
| 59 | struct dirent *f; | ||
| 60 | char file[PATH_MAX]; | ||
| 61 | long pos, remember = -1; | ||
| 62 | |||
| 63 | rewinddir(dp); | ||
| 64 | snprintf(file, sizeof file, "%d", i); | ||
| 65 | for (;;) { | ||
| 66 | pos = telldir(dp); | ||
| 67 | f = readdir(dp); | ||
| 68 | if (f == NULL) | ||
| 69 | break; | ||
| 70 | if (strcmp(file, f->d_name) == 0) | ||
| 71 | remember = pos; | ||
| 72 | } | ||
| 73 | if (remember == -1) | ||
| 74 | errx(1, "remember"); | ||
| 75 | seekdir(dp, remember); | ||
| 76 | if (telldir(dp) != remember) | ||
| 77 | errx(1, "tell after seek"); | ||
| 78 | if (telldir(dp) != remember) | ||
| 79 | errx(1, "tell after tell"); | ||
| 80 | f = readdir(dp); | ||
| 81 | if (f == NULL) | ||
| 82 | err(1, "seek to %s %ld", file, remember); | ||
| 83 | |||
| 84 | if (strcmp(f->d_name, file) != 0) | ||
| 85 | err(1, "name mismatch: %s != %s\n", f->d_name, file); | ||
| 86 | } | ||
| 87 | |||
| 88 | int | ||
| 89 | main(void) | ||
| 90 | { | ||
| 91 | DIR *dp; | ||
| 92 | int i; | ||
| 93 | |||
| 94 | createfiles(); | ||
| 95 | |||
| 96 | dp = opendir("d"); | ||
| 97 | if (dp == NULL) | ||
| 98 | err(1, "opendir"); | ||
| 99 | |||
| 100 | for (i = 0; i < NFILES; i++) | ||
| 101 | loop(dp, (i + 500) % NFILES); | ||
| 102 | |||
| 103 | closedir(dp); | ||
| 104 | delfiles(); | ||
| 105 | return 0; | ||
| 106 | } | ||
