• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
22 static int in_fd;
23 static int out_fd;
24 
setup(void)25 static 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 
cleanup(void)31 static void cleanup(void)
32 {
33 	SAFE_CLOSE(in_fd);
34 	SAFE_CLOSE(out_fd);
35 }
36 
run(void)37 static 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=%ld", offset);
43 }
44 
45 static struct tst_test test = {
46 	.needs_tmpdir = 1,
47 	.cleanup = cleanup,
48 	.setup = setup,
49 	.test_all = run,
50 };
51