1 /* Tests of mkfifo and friends.
2 Copyright (C) 2009-2017 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* Written by Eric Blake <ebb9@byu.net>, 2009. */
19 /* This file is designed to test mkfifo(n,m), mknod(n,m|S_IFIFO,0),
20 mkfifoat(AT_FDCWD,n,m), and mknodat(AT_FDCWD,n,m|S_IFIFO,0). FUNC
21 is the function to test. Assumes that BASE and ASSERT are already
22 defined, and that appropriate headers are already included. If
23 PRINT, warn before skipping symlink tests with status 77. */
26 test_mkfifo (int (*func
) (char const *, mode_t
), bool print
)
28 int result
= func (BASE
"fifo", 0600);
30 if (result
== -1 && errno
== ENOSYS
)
33 fputs ("skipping test: no support for named fifos\n", stderr
);
37 ASSERT (stat (BASE
"fifo", &st
) == 0);
38 ASSERT (S_ISFIFO (st
.st_mode
));
40 /* Sanity checks of failures. */
42 ASSERT (func ("", S_IRUSR
| S_IWUSR
) == -1);
43 ASSERT (errno
== ENOENT
);
45 ASSERT (func (".", 0600) == -1);
46 /* Allow HP-UX 11.11's EISDIR, even though POSIX says it's wrong,
47 since it doesn't really hurt anything and we lack the energy to
49 ASSERT (errno
== EEXIST
|| errno
== EINVAL
|| errno
== EISDIR
);
51 ASSERT (func (BASE
"fifo", 0600) == -1);
52 ASSERT (errno
== EEXIST
);
53 ASSERT (unlink (BASE
"fifo") == 0);
55 ASSERT (func (BASE
"fifo/", 0600) == -1);
56 ASSERT (errno
== ENOENT
|| errno
== ENOTDIR
);
58 /* Test trailing slash behavior. */
59 if (symlink (BASE
"fifo", BASE
"link"))
62 fputs ("skipping test: symlinks not supported on this file system\n",
67 ASSERT (func (BASE
"link", 0600) == -1);
68 ASSERT (errno
== EEXIST
);
70 ASSERT (func (BASE
"link/", 0600) == -1);
71 ASSERT (errno
== EEXIST
|| errno
== ENOENT
|| errno
== ENOTDIR
);
73 ASSERT (unlink (BASE
"fifo") == -1);
74 ASSERT (errno
== ENOENT
);
75 ASSERT (unlink (BASE
"link") == 0);