summaryrefslogtreecommitdiff
path: root/tests/test-open.h
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2025-10-18 19:06:52 +0200
committerJörg Frings-Fürst <debian@jff.email>2025-10-18 19:06:52 +0200
commit27dae84ed92f1ef0300263091972338d12e78348 (patch)
tree7c52931f474fafb8a4bd4fd15ca3461c77cdecc2 /tests/test-open.h
parent4682deeb62247d34de87f8e777f99e2d337fd377 (diff)
New upstream version 1.4.1upstream/1.4.1upstream
Diffstat (limited to 'tests/test-open.h')
-rw-r--r--tests/test-open.h48
1 files changed, 47 insertions, 1 deletions
diff --git a/tests/test-open.h b/tests/test-open.h
index 369c926f..1a80af45 100644
--- a/tests/test-open.h
+++ b/tests/test-open.h
@@ -1,5 +1,5 @@
/* Test of opening a file descriptor.
- Copyright (C) 2007-2024 Free Software Foundation, Inc.
+ Copyright (C) 2007-2025 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -41,9 +41,18 @@
static ALWAYS_INLINE int
test_open (int (*func) (char const *, int, ...), bool print)
{
+#if HAVE_DECL_ALARM
+ /* Declare failure if test takes too long, by using default abort
+ caused by SIGALRM. */
+ int alarm_value = 5;
+ signal (SIGALRM, SIG_DFL);
+ alarm (alarm_value);
+#endif
+
int fd;
/* Remove anything from prior partial run. */
+ unlink (BASE "fifo");
unlink (BASE "file");
unlink (BASE "e.exe");
unlink (BASE "link");
@@ -69,6 +78,43 @@ test_open (int (*func) (char const *, int, ...), bool print)
ASSERT (func (BASE "file/", O_RDONLY) == -1);
ASSERT (errno == ENOTDIR || errno == EISDIR || errno == EINVAL);
+ /* Cannot open regular file with O_DIRECTORY. */
+ errno = 0;
+ ASSERT (func (BASE "file", O_RDONLY | O_DIRECTORY) == -1);
+ ASSERT (errno == ENOTDIR);
+
+ /* Cannot open /dev/null with trailing slash or O_DIRECTORY. */
+ errno = 0;
+ ASSERT (func ("/dev/null/", O_RDONLY) == -1);
+#if defined _WIN32 && !defined __CYGWIN__
+ ASSERT (errno == ENOENT);
+#else
+ ASSERT (errno == ENOTDIR || errno == EISDIR || errno == EINVAL);
+#endif
+
+ errno = 0;
+ ASSERT (func ("/dev/null", O_RDONLY | O_DIRECTORY) == -1);
+ ASSERT (errno == ENOTDIR);
+
+ /* Cannot open /dev/tty with trailing slash or O_DIRECTORY,
+ though errno may differ as there may not be a controlling tty. */
+ ASSERT (func ("/dev/tty/", O_RDONLY) == -1);
+ ASSERT (func ("/dev/tty", O_RDONLY | O_DIRECTORY) == -1);
+
+ /* Cannot open fifo with trailing slash or O_DIRECTORY. */
+ if (mkfifo (BASE "fifo", 0666) == 0)
+ {
+ errno = 0;
+ ASSERT (func (BASE "fifo/", O_RDONLY) == -1);
+ ASSERT (errno == ENOTDIR || errno == EISDIR || errno == EINVAL);
+
+ errno = 0;
+ ASSERT (func (BASE "fifo", O_RDONLY | O_DIRECTORY) == -1);
+ ASSERT (errno == ENOTDIR);
+
+ ASSERT (unlink (BASE "fifo") == 0);
+ }
+
/* Directories cannot be opened for writing. */
errno = 0;
ASSERT (func (".", O_WRONLY) == -1);