1*e30a6200SEnji Cooper /*-
2*e30a6200SEnji Cooper * Copyright (c) 2010 Jilles Tjoelker
3*e30a6200SEnji Cooper * All rights reserved.
4*e30a6200SEnji Cooper *
5*e30a6200SEnji Cooper * Redistribution and use in source and binary forms, with or without
6*e30a6200SEnji Cooper * modification, are permitted provided that the following conditions
7*e30a6200SEnji Cooper * are met:
8*e30a6200SEnji Cooper * 1. Redistributions of source code must retain the above copyright
9*e30a6200SEnji Cooper * notice, this list of conditions and the following disclaimer.
10*e30a6200SEnji Cooper * 2. Redistributions in binary form must reproduce the above copyright
11*e30a6200SEnji Cooper * notice, this list of conditions and the following disclaimer in the
12*e30a6200SEnji Cooper * documentation and/or other materials provided with the distribution.
13*e30a6200SEnji Cooper *
14*e30a6200SEnji Cooper * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15*e30a6200SEnji Cooper * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16*e30a6200SEnji Cooper * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17*e30a6200SEnji Cooper * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18*e30a6200SEnji Cooper * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19*e30a6200SEnji Cooper * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20*e30a6200SEnji Cooper * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21*e30a6200SEnji Cooper * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22*e30a6200SEnji Cooper * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23*e30a6200SEnji Cooper * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24*e30a6200SEnji Cooper * SUCH DAMAGE.
25*e30a6200SEnji Cooper */
26*e30a6200SEnji Cooper
27*e30a6200SEnji Cooper #include <sys/select.h>
28*e30a6200SEnji Cooper
29*e30a6200SEnji Cooper #include <err.h>
30*e30a6200SEnji Cooper #include <stdio.h>
31*e30a6200SEnji Cooper #include <unistd.h>
32*e30a6200SEnji Cooper
33*e30a6200SEnji Cooper /*
34*e30a6200SEnji Cooper * Check that pipes can be selected for writing in the reverse direction.
35*e30a6200SEnji Cooper */
36*e30a6200SEnji Cooper int
main(void)37*e30a6200SEnji Cooper main(void)
38*e30a6200SEnji Cooper {
39*e30a6200SEnji Cooper int pip[2];
40*e30a6200SEnji Cooper fd_set set;
41*e30a6200SEnji Cooper int n;
42*e30a6200SEnji Cooper
43*e30a6200SEnji Cooper if (pipe(pip) == -1)
44*e30a6200SEnji Cooper err(1, "FAIL: pipe");
45*e30a6200SEnji Cooper
46*e30a6200SEnji Cooper FD_ZERO(&set);
47*e30a6200SEnji Cooper FD_SET(pip[0], &set);
48*e30a6200SEnji Cooper n = select(pip[1] + 1, NULL, &set, NULL, &(struct timeval){ 0, 0 });
49*e30a6200SEnji Cooper if (n != 1)
50*e30a6200SEnji Cooper errx(1, "FAIL: select initial reverse direction");
51*e30a6200SEnji Cooper
52*e30a6200SEnji Cooper n = write(pip[0], "x", 1);
53*e30a6200SEnji Cooper if (n != 1)
54*e30a6200SEnji Cooper err(1, "FAIL: write reverse direction");
55*e30a6200SEnji Cooper
56*e30a6200SEnji Cooper FD_ZERO(&set);
57*e30a6200SEnji Cooper FD_SET(pip[0], &set);
58*e30a6200SEnji Cooper n = select(pip[1] + 1, NULL, &set, NULL, &(struct timeval){ 0, 0 });
59*e30a6200SEnji Cooper if (n != 1)
60*e30a6200SEnji Cooper errx(1, "FAIL: select reverse direction after write");
61*e30a6200SEnji Cooper
62*e30a6200SEnji Cooper printf("PASS\n");
63*e30a6200SEnji Cooper
64*e30a6200SEnji Cooper return (0);
65*e30a6200SEnji Cooper }
66