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