diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/regress/lib/libc/telldir/Makefile | 8 | ||||
| -rw-r--r-- | src/regress/lib/libc/telldir/main.c | 14 | ||||
| -rw-r--r-- | src/regress/lib/libc/telldir/shortseek.c | 91 | ||||
| -rw-r--r-- | src/regress/lib/libc/telldir/telldir.c | 73 | ||||
| -rw-r--r-- | src/regress/lib/libc/telldir/utils.c | 53 | ||||
| -rw-r--r-- | src/regress/lib/libc/telldir/utils.h | 6 | 
6 files changed, 189 insertions, 56 deletions
| diff --git a/src/regress/lib/libc/telldir/Makefile b/src/regress/lib/libc/telldir/Makefile index 0927779663..728ae90e1e 100644 --- a/src/regress/lib/libc/telldir/Makefile +++ b/src/regress/lib/libc/telldir/Makefile | |||
| @@ -1,5 +1,9 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2006/03/25 20:27:11 otto Exp $ | 1 | # $OpenBSD: Makefile,v 1.2 2013/11/03 00:20:24 schwarze Exp $ | 
| 2 | 2 | ||
| 3 | PROG= telldir | 3 | PROG = telldir | 
| 4 | SRCS = utils.c shortseek.c telldir.c main.c | ||
| 5 | |||
| 6 | cleandir: | ||
| 7 | rm -rf d | ||
| 4 | 8 | ||
| 5 | .include <bsd.regress.mk> | 9 | .include <bsd.regress.mk> | 
| diff --git a/src/regress/lib/libc/telldir/main.c b/src/regress/lib/libc/telldir/main.c new file mode 100644 index 0000000000..23ffa65dbf --- /dev/null +++ b/src/regress/lib/libc/telldir/main.c | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | /* $OpenBSD: main.c,v 1.1 2013/11/03 00:20:24 schwarze Exp $ */ | ||
| 2 | |||
| 3 | /* Written by Ingo Schwarze, 2013, Public domain. */ | ||
| 4 | |||
| 5 | void shortseek(void); | ||
| 6 | void longseek(void); | ||
| 7 | |||
| 8 | int | ||
| 9 | main(void) | ||
| 10 | { | ||
| 11 | shortseek(); | ||
| 12 | longseek(); | ||
| 13 | return(0); | ||
| 14 | } | ||
| diff --git a/src/regress/lib/libc/telldir/shortseek.c b/src/regress/lib/libc/telldir/shortseek.c new file mode 100644 index 0000000000..9b2141ab4c --- /dev/null +++ b/src/regress/lib/libc/telldir/shortseek.c | |||
| @@ -0,0 +1,91 @@ | |||
| 1 | /* $OpenBSD: shortseek.c,v 1.1 2013/11/03 00:20:24 schwarze Exp $ */ | ||
| 2 | |||
| 3 | /* Written by Otto Moerbeek, 2006, Public domain. */ | ||
| 4 | /* Modified by Ingo Schwarze, 2013, Public domain. */ | ||
| 5 | |||
| 6 | #include <sys/types.h> | ||
| 7 | #include <dirent.h> | ||
| 8 | #include <err.h> | ||
| 9 | #include <limits.h> | ||
| 10 | #include <stdio.h> | ||
| 11 | #include <string.h> | ||
| 12 | |||
| 13 | #include "utils.h" | ||
| 14 | |||
| 15 | #define NFILES 5 | ||
| 16 | |||
| 17 | static void | ||
| 18 | shortloop(DIR *dp, int iend, int iback) | ||
| 19 | { | ||
| 20 | struct dirent *f; | ||
| 21 | char fend[PATH_MAX], fback[PATH_MAX]; | ||
| 22 | long pos, t, remember = -1; | ||
| 23 | int i; | ||
| 24 | |||
| 25 | rewinddir(dp); | ||
| 26 | snprintf(fend, sizeof fend, "%d", iend); | ||
| 27 | snprintf(fback, sizeof fback, "%d", iback); | ||
| 28 | |||
| 29 | /* Scan to iend, remember where iback is. */ | ||
| 30 | |||
| 31 | for (;;) { | ||
| 32 | pos = telldir(dp); | ||
| 33 | f = readdir(dp); | ||
| 34 | if (f == NULL) | ||
| 35 | errx(1, "file %s not found", fend); | ||
| 36 | if (strcmp(fback, f->d_name) == 0) | ||
| 37 | remember = pos; | ||
| 38 | if (strcmp(fend, f->d_name) == 0) | ||
| 39 | break; | ||
| 40 | } | ||
| 41 | if (remember == -1) | ||
| 42 | errx(1, "file %s not found", fback); | ||
| 43 | |||
| 44 | /* Go back to iback, checking seekdir, telldir and readdir. */ | ||
| 45 | |||
| 46 | seekdir(dp, remember); | ||
| 47 | if ((t = telldir(dp)) != remember) | ||
| 48 | errx(1, "tell after seek %s %ld != %ld", fback, t, remember); | ||
| 49 | if ((t = telldir(dp)) != remember) | ||
| 50 | errx(1, "tell after tell %s %ld != %ld", fback, t, remember); | ||
| 51 | f = readdir(dp); | ||
| 52 | if (f == NULL) | ||
| 53 | errx(1, "readdir %s at %ld", fback, remember); | ||
| 54 | |||
| 55 | if (strcmp(f->d_name, fback)) | ||
| 56 | errx(1, "name mismatch: %s != %s", f->d_name, fback); | ||
| 57 | |||
| 58 | /* Check that readdir can iterate the remaining files. */ | ||
| 59 | |||
| 60 | for (i = iback + 1; i < NFILES; i++) { | ||
| 61 | f = readdir(dp); | ||
| 62 | if (f == NULL) | ||
| 63 | errx(1, "readdir %i failed", i); | ||
| 64 | } | ||
| 65 | |||
| 66 | /* Check that readdir stops at the right place. */ | ||
| 67 | |||
| 68 | f = readdir(dp); | ||
| 69 | if (f != NULL) | ||
| 70 | errx(1, "readdir %i returned %s", NFILES, f->d_name); | ||
| 71 | } | ||
| 72 | |||
| 73 | void | ||
| 74 | shortseek(void) | ||
| 75 | { | ||
| 76 | DIR *dp; | ||
| 77 | int iend, iback; | ||
| 78 | |||
| 79 | createfiles(NFILES); | ||
| 80 | |||
| 81 | dp = opendir("d"); | ||
| 82 | if (dp == NULL) | ||
| 83 | err(1, "shortseek: opendir"); | ||
| 84 | |||
| 85 | for (iend = 0; iend < NFILES; iend++) | ||
| 86 | for (iback = 0; iback <= iend; iback++) | ||
| 87 | shortloop(dp, iend, iback); | ||
| 88 | |||
| 89 | closedir(dp); | ||
| 90 | delfiles(); | ||
| 91 | } | ||
| diff --git a/src/regress/lib/libc/telldir/telldir.c b/src/regress/lib/libc/telldir/telldir.c index 9de0eb5e96..d2879cc701 100644 --- a/src/regress/lib/libc/telldir/telldir.c +++ b/src/regress/lib/libc/telldir/telldir.c | |||
| @@ -1,60 +1,20 @@ | |||
| 1 | /* $OpenBSD: telldir.c,v 1.3 2013/08/20 01:13:54 guenther Exp $ */ | 1 | /* $OpenBSD: telldir.c,v 1.4 2013/11/03 00:20:24 schwarze Exp $ */ | 
| 2 | 2 | ||
| 3 | /* Written by Otto Moerbeek, 2006, Public domain. */ | 3 | /* Written by Otto Moerbeek, 2006, Public domain. */ | 
| 4 | 4 | ||
| 5 | #include <sys/types.h> | 5 | #include <sys/types.h> | 
| 6 | #include <sys/stat.h> | ||
| 7 | #include <dirent.h> | 6 | #include <dirent.h> | 
| 8 | #include <err.h> | 7 | #include <err.h> | 
| 9 | #include <limits.h> | 8 | #include <limits.h> | 
| 10 | #include <fcntl.h> | ||
| 11 | #include <stdio.h> | 9 | #include <stdio.h> | 
| 12 | #include <string.h> | 10 | #include <string.h> | 
| 13 | #include <unistd.h> | ||
| 14 | 11 | ||
| 12 | #include "utils.h" | ||
| 15 | 13 | ||
| 16 | #define NFILES 1000 | 14 | #define NFILES 1000 | 
| 17 | 15 | ||
| 18 | void | 16 | static void | 
| 19 | createfiles(void) | 17 | longloop(DIR *dp, int i) | 
| 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 | { | 18 | { | 
| 59 | struct dirent *f; | 19 | struct dirent *f; | 
| 60 | char file[PATH_MAX]; | 20 | char file[PATH_MAX]; | 
| @@ -62,6 +22,9 @@ loop(DIR *dp, int i) | |||
| 62 | 22 | ||
| 63 | rewinddir(dp); | 23 | rewinddir(dp); | 
| 64 | snprintf(file, sizeof file, "%d", i); | 24 | snprintf(file, sizeof file, "%d", i); | 
| 25 | |||
| 26 | /* Scan through all files, remember where file i is. */ | ||
| 27 | |||
| 65 | for (;;) { | 28 | for (;;) { | 
| 66 | pos = telldir(dp); | 29 | pos = telldir(dp); | 
| 67 | f = readdir(dp); | 30 | f = readdir(dp); | 
| @@ -72,35 +35,37 @@ loop(DIR *dp, int i) | |||
| 72 | } | 35 | } | 
| 73 | if (remember == -1) | 36 | if (remember == -1) | 
| 74 | errx(1, "remember %s", file); | 37 | errx(1, "remember %s", file); | 
| 38 | |||
| 39 | /* Go back to i, checking seekdir, telldir and readdir. */ | ||
| 40 | |||
| 75 | seekdir(dp, remember); | 41 | seekdir(dp, remember); | 
| 76 | if ((t = telldir(dp)) != remember) | 42 | if ((t = telldir(dp)) != remember) | 
| 77 | errx(1, "tell after seek %s %ld != %ld", file, t, pos); | 43 | errx(1, "tell after seek %s %ld != %ld", file, t, remember); | 
| 78 | if ((t = telldir(dp)) != remember) | 44 | if ((t = telldir(dp)) != remember) | 
| 79 | errx(1, "tell after tell %s %ld != %ld", file, t, pos); | 45 | errx(1, "tell after tell %s %ld != %ld", file, t, remember); | 
| 80 | f = readdir(dp); | 46 | f = readdir(dp); | 
| 81 | if (f == NULL) | 47 | if (f == NULL) | 
| 82 | err(1, "seek to %s %ld", file, remember); | 48 | errx(1, "readdir %s at %ld", file, remember); | 
| 83 | 49 | ||
| 84 | if (strcmp(f->d_name, file) != 0) | 50 | if (strcmp(f->d_name, file) != 0) | 
| 85 | err(1, "name mismatch: %s != %s\n", f->d_name, file); | 51 | errx(1, "name mismatch: %s != %s", f->d_name, file); | 
| 86 | } | 52 | } | 
| 87 | 53 | ||
| 88 | int | 54 | void | 
| 89 | main(void) | 55 | longseek(void) | 
| 90 | { | 56 | { | 
| 91 | DIR *dp; | 57 | DIR *dp; | 
| 92 | int i; | 58 | int i; | 
| 93 | 59 | ||
| 94 | createfiles(); | 60 | createfiles(NFILES); | 
| 95 | 61 | ||
| 96 | dp = opendir("d"); | 62 | dp = opendir("d"); | 
| 97 | if (dp == NULL) | 63 | if (dp == NULL) | 
| 98 | err(1, "opendir"); | 64 | err(1, "longseek: opendir"); | 
| 99 | 65 | ||
| 100 | for (i = 0; i < NFILES; i++) | 66 | for (i = 0; i < NFILES; i++) | 
| 101 | loop(dp, (i + NFILES/2) % NFILES); | 67 | longloop(dp, (i + NFILES/2) % NFILES); | 
| 102 | 68 | ||
| 103 | closedir(dp); | 69 | closedir(dp); | 
| 104 | delfiles(); | 70 | delfiles(); | 
| 105 | return 0; | ||
| 106 | } | 71 | } | 
| diff --git a/src/regress/lib/libc/telldir/utils.c b/src/regress/lib/libc/telldir/utils.c new file mode 100644 index 0000000000..6a4101aba3 --- /dev/null +++ b/src/regress/lib/libc/telldir/utils.c | |||
| @@ -0,0 +1,53 @@ | |||
| 1 | /* $OpenBSD: utils.c,v 1.1 2013/11/03 00:20:24 schwarze 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 <fcntl.h> | ||
| 10 | #include <limits.h> | ||
| 11 | #include <stdio.h> | ||
| 12 | #include <string.h> | ||
| 13 | #include <unistd.h> | ||
| 14 | |||
| 15 | #include "utils.h" | ||
| 16 | |||
| 17 | void | ||
| 18 | createfiles(int nfiles) | ||
| 19 | { | ||
| 20 | int i, fd; | ||
| 21 | char file[PATH_MAX]; | ||
| 22 | |||
| 23 | mkdir("d", 0755); | ||
| 24 | for (i = 0; i < nfiles; i++) { | ||
| 25 | snprintf(file, sizeof file, "d/%d", i); | ||
| 26 | if ((fd = open(file, O_CREAT | O_WRONLY, 0600)) == -1) | ||
| 27 | err(1, "open %s", file); | ||
| 28 | close(fd); | ||
| 29 | } | ||
| 30 | } | ||
| 31 | |||
| 32 | void | ||
| 33 | delfiles(void) | ||
| 34 | { | ||
| 35 | DIR *dp; | ||
| 36 | struct dirent *f; | ||
| 37 | char file[PATH_MAX]; | ||
| 38 | |||
| 39 | dp = opendir("d"); | ||
| 40 | if (dp == NULL) | ||
| 41 | err(1, "opendir"); | ||
| 42 | while (f = readdir(dp)) { | ||
| 43 | if (strcmp(f->d_name, ".") == 0 || | ||
| 44 | strcmp(f->d_name, "..") == 0) | ||
| 45 | continue; | ||
| 46 | snprintf(file, sizeof file, "d/%s", f->d_name); | ||
| 47 | if (unlink(file) == -1) | ||
| 48 | err(1, "unlink %s", f->d_name); | ||
| 49 | } | ||
| 50 | closedir(dp); | ||
| 51 | if (rmdir("d") == -1) | ||
| 52 | err(1, "rmdir"); | ||
| 53 | } | ||
| diff --git a/src/regress/lib/libc/telldir/utils.h b/src/regress/lib/libc/telldir/utils.h new file mode 100644 index 0000000000..74ffcd4641 --- /dev/null +++ b/src/regress/lib/libc/telldir/utils.h | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | /* $OpenBSD: utils.h,v 1.1 2013/11/03 00:20:24 schwarze Exp $ */ | ||
| 2 | |||
| 3 | /* Written by Ingo Schwarze, 2013, Public domain. */ | ||
| 4 | |||
| 5 | void createfiles(int); | ||
| 6 | void delfiles(void); | ||
