From 92310eb0400efc52093dc7597258a25953dee16b Mon Sep 17 00:00:00 2001 From: schwarze <> Date: Sun, 3 Nov 2013 00:20:24 +0000 Subject: Add a second test, shortseek(), to make sure that seekdir() also works correctly when moving the directory pointer by small distances. This is currently failing, i will send an updated libc/gen patch to fix this right afterwards. Move the functions createfiles() and delfiles() to utils.{h,c} for reuse. Minor cleanup in telldir.c. --- src/regress/lib/libc/telldir/utils.c | 53 ++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/regress/lib/libc/telldir/utils.c (limited to 'src/regress/lib/libc/telldir/utils.c') 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 @@ +/* $OpenBSD: utils.c,v 1.1 2013/11/03 00:20:24 schwarze Exp $ */ + +/* Written by Otto Moerbeek, 2006, Public domain. */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "utils.h" + +void +createfiles(int nfiles) +{ + int i, fd; + char file[PATH_MAX]; + + mkdir("d", 0755); + for (i = 0; i < nfiles; i++) { + snprintf(file, sizeof file, "d/%d", i); + if ((fd = open(file, O_CREAT | O_WRONLY, 0600)) == -1) + err(1, "open %s", file); + close(fd); + } +} + +void +delfiles(void) +{ + DIR *dp; + struct dirent *f; + char file[PATH_MAX]; + + dp = opendir("d"); + if (dp == NULL) + err(1, "opendir"); + while (f = readdir(dp)) { + if (strcmp(f->d_name, ".") == 0 || + strcmp(f->d_name, "..") == 0) + continue; + snprintf(file, sizeof file, "d/%s", f->d_name); + if (unlink(file) == -1) + err(1, "unlink %s", f->d_name); + } + closedir(dp); + if (rmdir("d") == -1) + err(1, "rmdir"); +} -- cgit v1.2.3-55-g6feb