1228512Sjilles/*- 2228512Sjilles * Copyright (c) 2010 Jilles Tjoelker 3228512Sjilles * All rights reserved. 4228512Sjilles * 5228512Sjilles * Redistribution and use in source and binary forms, with or without 6228512Sjilles * modification, are permitted provided that the following conditions 7228512Sjilles * are met: 8228512Sjilles * 1. Redistributions of source code must retain the above copyright 9228512Sjilles * notice, this list of conditions and the following disclaimer. 10228512Sjilles * 2. Redistributions in binary form must reproduce the above copyright 11228512Sjilles * notice, this list of conditions and the following disclaimer in the 12228512Sjilles * documentation and/or other materials provided with the distribution. 13228512Sjilles * 14228512Sjilles * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15228512Sjilles * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16228512Sjilles * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17228512Sjilles * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18228512Sjilles * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19228512Sjilles * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20228512Sjilles * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21228512Sjilles * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22228512Sjilles * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23228512Sjilles * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24228512Sjilles * SUCH DAMAGE. 25228512Sjilles * 26228512Sjilles * $FreeBSD$ 27228512Sjilles */ 28228512Sjilles 29290914Sngie#include <sys/select.h> 30228512Sjilles 31290914Sngie#include <err.h> 32290914Sngie#include <stdio.h> 33290914Sngie#include <unistd.h> 34228512Sjilles 35228512Sjilles/* 36228512Sjilles * Check that pipes can be selected for writing in the reverse direction. 37228512Sjilles */ 38228512Sjillesint 39290914Sngiemain(void) 40228512Sjilles{ 41228512Sjilles int pip[2]; 42228512Sjilles fd_set set; 43228512Sjilles int n; 44228512Sjilles 45228512Sjilles if (pipe(pip) == -1) 46228512Sjilles err(1, "FAIL: pipe"); 47228512Sjilles 48228512Sjilles FD_ZERO(&set); 49228512Sjilles FD_SET(pip[0], &set); 50228512Sjilles n = select(pip[1] + 1, NULL, &set, NULL, &(struct timeval){ 0, 0 }); 51228512Sjilles if (n != 1) 52228512Sjilles errx(1, "FAIL: select initial reverse direction"); 53228512Sjilles 54228512Sjilles n = write(pip[0], "x", 1); 55228512Sjilles if (n != 1) 56228512Sjilles err(1, "FAIL: write reverse direction"); 57228512Sjilles 58228512Sjilles FD_ZERO(&set); 59228512Sjilles FD_SET(pip[0], &set); 60228512Sjilles n = select(pip[1] + 1, NULL, &set, NULL, &(struct timeval){ 0, 0 }); 61228512Sjilles if (n != 1) 62228512Sjilles errx(1, "FAIL: select reverse direction after write"); 63228512Sjilles 64228512Sjilles printf("PASS\n"); 65228512Sjilles 66228512Sjilles return (0); 67228512Sjilles} 68