1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * Copyright (c) International Business Machines Corp., 2002 4 * Copyright (c) 2003-2023 Linux Test Project 5 */ 6 7/*\ 8 * [Description] 9 * 10 * Verify that, an attempt to write to the read end of a pipe fails with EBADF 11 * and an attempt to read from the write end of a pipe also fails with EBADF. 12 */ 13 14#include "tst_test.h" 15 16static int fd[2]; 17 18static void verify_pipe(void) 19{ 20 char buf[] = "abcdef"; 21 22 SAFE_PIPE(fd); 23 24 TST_EXP_FAIL2(write(fd[0], "A", 1), EBADF); 25 TST_EXP_FAIL2(read(fd[1], buf, 1), EBADF); 26 27 SAFE_CLOSE(fd[0]); 28 SAFE_CLOSE(fd[1]); 29} 30 31static void cleanup(void) 32{ 33 if (fd[0] > 0) 34 SAFE_CLOSE(fd[0]); 35 if (fd[1] > 0) 36 SAFE_CLOSE(fd[1]); 37} 38 39static struct tst_test test = { 40 .test_all = verify_pipe, 41 .cleanup = cleanup 42}; 43