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