1 /* $NetBSD: h_fileactions.c,v 1.1 2012/02/13 21:03:08 martin Exp $ */
4 * Copyright (c) 2012 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles Zhang <charles@NetBSD.org> and
9 * Martin Husemann <martin@NetBSD.org>.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
43 * This checks (hardcoded) the assumptions that are setup from the
44 * main test program via posix spawn file actions.
45 * Program exits with EXIT_SUCCESS or EXIT_FAILURE accordingly
46 * (and does some stderr diagnostics in case of errors).
49 main(int argc
, char **argv
)
51 int res
= EXIT_SUCCESS
;
55 strcpy(buf
, "test...");
56 /* file desc 3 should be closed via addclose */
57 if (read(3, buf
, BUFSIZE
) != -1 || errno
!= EBADF
) {
58 fprintf(stderr
, "%s: filedesc 3 is not closed\n",
62 /* file desc 4 should be closed via closeonexec */
63 if (read(4, buf
, BUFSIZE
) != -1 || errno
!= EBADF
) {
64 fprintf(stderr
, "%s: filedesc 4 is not closed\n",
68 /* file desc 5 remains open */
69 if (write(5, buf
, BUFSIZE
) <= 0) {
70 fprintf(stderr
, "%s: could not write to filedesc 5\n",
74 /* file desc 6 should be open (via addopen) */
75 if (write(6, buf
, BUFSIZE
) <= 0) {
76 fprintf(stderr
, "%s: could not write to filedesc 6\n",
80 /* file desc 7 should refer to stdout */
82 if (fstat(fileno(stdout
), &sb0
) != 0) {
83 fprintf(stderr
, "%s: could not fstat stdout\n",
87 if (fstat(7, &sb1
) != 0) {
88 fprintf(stderr
, "%s: could not fstat filedesc 7\n",
92 if (write(7, buf
, strlen(buf
)) <= 0) {
93 fprintf(stderr
, "%s: could not write to filedesc 7\n",
97 if (memcmp(&sb0
, &sb1
, sizeof sb0
) != 0) {
98 fprintf(stderr
, "%s: stat results differ\n", getprogname());