• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2017 Carlo Marcelo Arenas Belon <carlo@gmail.com>
3  * Copyright (c) 2018 Cyril Hrubis <chrubis@suse.cz>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 /*
19  * Tests for a special case NULL buffer with size 0 is expected to return 0.
20  */
21 
22 #include <errno.h>
23 #include "tst_test.h"
24 
25 static int fd;
26 
verify_pwrite(void)27 static void verify_pwrite(void)
28 {
29 	TEST(pwrite(fd, NULL, 0, 0));
30 
31 	if (TST_RET != 0) {
32 		tst_res(TFAIL | TTERRNO,
33 			"pwrite() should have succeeded with ret=0");
34 		return;
35 	}
36 
37 	tst_res(TPASS, "pwrite(fd, NULL, 0) == 0");
38 }
39 
setup(void)40 static void setup(void)
41 {
42 	fd = SAFE_OPEN("test_file", O_RDWR | O_CREAT, 0700);
43 }
44 
cleanup(void)45 static void cleanup(void)
46 {
47 	if (fd > 0)
48 		SAFE_CLOSE(fd);
49 }
50 
51 static struct tst_test test = {
52 	.setup = setup,
53 	.cleanup = cleanup,
54 	.test_all = verify_pwrite,
55 	.needs_tmpdir = 1,
56 };
57