+struct test_file *
+get_tf(void)
+{
+ unsigned index = 0;
+
+ switch (fd_policy) {
+ case FD_ROTATE:
+ index = fd_last++;
+ break;
+ case FD_RANDOM:
+ index = random();
+ break;
+ case FD_SINGLE:
+ index = 0;
+ break;
+ default:
+ prt("unknown policy");
+ exit(1);
+ break;
+ }
+ return &test_files[ index % num_test_files ];
+}
+
+void
+assign_fd_policy(char *policy)
+{
+ if (!strcmp(policy, "random"))
+ fd_policy = FD_RANDOM;
+ else if (!strcmp(policy, "rotate"))
+ fd_policy = FD_ROTATE;
+ else {
+ prt("unknown -I policy: '%s'\n", policy);
+ exit(1);
+ }
+}
+
+int
+get_fd(void)
+{
+ struct test_file *tf = get_tf();
+ return tf->fd;
+}
+
+static const char *my_basename(const char *path)
+{
+ char *c = strrchr(path, '/');
+
+ return c ? c++ : path;
+}
+
+void
+open_test_files(char **argv, int argc)
+{
+ struct test_file *tf;
+ int i;
+
+ num_test_files = argc;
+ if (num_test_files == 1)
+ fd_policy = FD_SINGLE;
+
+ test_files = calloc(num_test_files, sizeof(*test_files));
+ if (test_files == NULL) {
+ prterr("reallocating space for test files");
+ exit(1);
+ }
+
+ for (i = 0, tf = test_files; i < num_test_files; i++, tf++) {
+
+ tf->path = argv[i];
+ tf->fd = open(tf->path, O_RDWR|(lite ? 0 : O_CREAT|O_TRUNC),
+ 0666);
+ if (tf->fd < 0) {
+ prterr(tf->path);
+ exit(91);
+ }
+ }
+
+ if (quiet || fd_policy == FD_SINGLE)
+ return;
+
+ for (i = 0, tf = test_files; i < num_test_files; i++, tf++)
+ prt("fd %d: %s\n", i, tf->path);
+}
+
+void
+close_test_files(void)
+{
+ int i;
+ struct test_file *tf;
+
+ for (i = 0, tf = test_files; i < num_test_files; i++, tf++) {
+ if (close(tf->fd)) {
+ prterr("close");
+ report_failure(99);
+ }
+ }
+}
+