2 * Copyright (c) 2014 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
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
36 static int testnum = 1;
39 runtest(const char *fname, int intmode, const char *strmode, bool success)
44 fd = open(fname, intmode);
46 printf("not ok %d - open(\"%s\", %#x) failed\n",
47 testnum++, fname, intmode);
50 fp = fdopen(fd, strmode);
55 "fdopen(open(\"%s\", %#x), \"%s\") failed\n",
56 testnum++, fname, intmode, strmode);
59 "fdopen(open(\"%s\", %#x), \"%s\") failed\n",
60 testnum++, fname, intmode, strmode);
65 "fdopen(open(\"%s\", %#x), \"%s\") succeeded\n",
66 testnum++, fname, intmode, strmode);
69 "fdopen(open(\"%s\", %#x), \"%s\") succeeded\n",
70 testnum++, fname, intmode, strmode);
75 * Test program for fdopen().
78 main(int argc, char *argv[])
81 runtest("/dev/null", O_RDONLY, "r", true);
82 runtest("/dev/null", O_WRONLY, "r", false);
83 runtest("/dev/null", O_RDWR, "r", true);
84 runtest("/dev/null", O_RDONLY, "w", false);
85 runtest("/dev/null", O_WRONLY, "w", true);
86 runtest("/dev/null", O_RDWR, "w", true);
87 runtest("/dev/null", O_RDONLY, "a", false);
88 runtest("/dev/null", O_WRONLY, "a", true);
89 runtest("/dev/null", O_RDWR, "a", true);
90 runtest("/dev/null", O_RDONLY, "r+", false);
91 runtest("/dev/null", O_WRONLY, "r+", false);
92 runtest("/dev/null", O_RDWR, "r+", true);
93 runtest("/dev/null", O_RDONLY, "w+", false);
94 runtest("/dev/null", O_WRONLY, "w+", false);
95 runtest("/dev/null", O_RDWR, "w+", true);
96 runtest("/bin/sh", O_EXEC, "r", false);
97 runtest("/bin/sh", O_EXEC, "w", false);
98 runtest("/bin/sh", O_EXEC, "r+", false);
99 runtest("/bin/sh", O_EXEC, "w+", false);