2 * Copyright (c) 2013 Jilles Tjoelker
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
36 * O_ACCMODE is currently defined incorrectly. This is what it should be.
37 * Various code depends on the incorrect value.
39 #define CORRECT_O_ACCMODE (O_ACCMODE | O_EXEC)
44 subtests(const char *path, int omode, const char *omodetext)
46 int fd, flags1, flags2, flags3;
48 fd = open(path, omode);
50 printf("not ok %d - open(\"%s\", %s) failed\n",
51 testnum++, path, omodetext);
53 printf("ok %d - open(\"%s\", %s) succeeded\n",
54 testnum++, path, omodetext);
55 flags1 = fcntl(fd, F_GETFL);
57 printf("not ok %d - fcntl(F_GETFL) failed\n", testnum++);
58 else if ((flags1 & CORRECT_O_ACCMODE) == omode)
59 printf("ok %d - fcntl(F_GETFL) gave correct result\n",
62 printf("not ok %d - fcntl(F_GETFL) gave incorrect result "
63 "(%#x & %#x != %#x)\n",
64 testnum++, flags1, CORRECT_O_ACCMODE, omode);
65 if (fcntl(fd, F_SETFL, flags1) == -1)
66 printf("not ok %d - fcntl(F_SETFL) same flags failed\n",
69 printf("ok %d - fcntl(F_SETFL) same flags succeeded\n",
71 flags2 = fcntl(fd, F_GETFL);
73 printf("not ok %d - fcntl(F_GETFL) failed\n", testnum++);
74 else if (flags2 == flags1)
75 printf("ok %d - fcntl(F_GETFL) gave same result\n",
78 printf("not ok %d - fcntl(F_SETFL) caused fcntl(F_GETFL) to "
79 "change from %#x to %#x\n",
80 testnum++, flags1, flags2);
81 if (fcntl(fd, F_SETFL, flags2 | O_NONBLOCK) == -1)
82 printf("not ok %d - fcntl(F_SETFL) O_NONBLOCK failed\n",
85 printf("ok %d - fcntl(F_SETFL) O_NONBLOCK succeeded\n",
87 flags3 = fcntl(fd, F_GETFL);
89 printf("not ok %d - fcntl(F_GETFL) failed\n", testnum++);
90 else if (flags3 == (flags2 | O_NONBLOCK))
91 printf("ok %d - fcntl(F_GETFL) gave expected result\n",
94 printf("not ok %d - fcntl(F_SETFL) gave unexpected result "
96 testnum++, flags3, flags2 | O_NONBLOCK);
101 main(int argc __unused, char **argv __unused)
105 subtests("/dev/null", O_RDONLY, "O_RDONLY");
106 subtests("/dev/null", O_WRONLY, "O_WRONLY");
107 subtests("/dev/null", O_RDWR, "O_RDWR");
108 subtests("/bin/sh", O_EXEC, "O_EXEC");