1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) International Business Machines Corp., 2001 4f08c3bdfSopenharmony_ci * Copyright (c) Red Hat Inc., 2007 5f08c3bdfSopenharmony_ci * 11/2007 Copyed from sendfile02.c by Masatake YAMATO 6f08c3bdfSopenharmony_ci */ 7f08c3bdfSopenharmony_ci 8f08c3bdfSopenharmony_ci/*\ 9f08c3bdfSopenharmony_ci * [Description] 10f08c3bdfSopenharmony_ci * 11f08c3bdfSopenharmony_ci * Testcase to test that sendfile(2) system call returns EINVAL when passing 12f08c3bdfSopenharmony_ci * negative offset. 13f08c3bdfSopenharmony_ci * 14f08c3bdfSopenharmony_ci * [Algorithm] 15f08c3bdfSopenharmony_ci * 16f08c3bdfSopenharmony_ci * Call sendfile with offset = -1. 17f08c3bdfSopenharmony_ci */ 18f08c3bdfSopenharmony_ci 19f08c3bdfSopenharmony_ci#include <sys/sendfile.h> 20f08c3bdfSopenharmony_ci#include "tst_test.h" 21f08c3bdfSopenharmony_ci 22f08c3bdfSopenharmony_cistatic int in_fd; 23f08c3bdfSopenharmony_cistatic int out_fd; 24f08c3bdfSopenharmony_ci 25f08c3bdfSopenharmony_cistatic void setup(void) 26f08c3bdfSopenharmony_ci{ 27f08c3bdfSopenharmony_ci in_fd = SAFE_OPEN("in_file", O_CREAT | O_RDWR, 0600); 28f08c3bdfSopenharmony_ci out_fd = SAFE_CREAT("out_file", 0600); 29f08c3bdfSopenharmony_ci} 30f08c3bdfSopenharmony_ci 31f08c3bdfSopenharmony_cistatic void cleanup(void) 32f08c3bdfSopenharmony_ci{ 33f08c3bdfSopenharmony_ci SAFE_CLOSE(in_fd); 34f08c3bdfSopenharmony_ci SAFE_CLOSE(out_fd); 35f08c3bdfSopenharmony_ci} 36f08c3bdfSopenharmony_ci 37f08c3bdfSopenharmony_cistatic void run(void) 38f08c3bdfSopenharmony_ci{ 39f08c3bdfSopenharmony_ci off_t offset = -1; 40f08c3bdfSopenharmony_ci 41f08c3bdfSopenharmony_ci TST_EXP_FAIL(sendfile(out_fd, in_fd, &offset, 1), EINVAL, 42f08c3bdfSopenharmony_ci "sendfile(out, in, &offset, ..) with offset=%lld", 43f08c3bdfSopenharmony_ci (long long int)offset); 44f08c3bdfSopenharmony_ci} 45f08c3bdfSopenharmony_ci 46f08c3bdfSopenharmony_cistatic struct tst_test test = { 47f08c3bdfSopenharmony_ci .needs_tmpdir = 1, 48f08c3bdfSopenharmony_ci .cleanup = cleanup, 49f08c3bdfSopenharmony_ci .setup = setup, 50f08c3bdfSopenharmony_ci .test_all = run, 51f08c3bdfSopenharmony_ci}; 52