xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/pwrite/pwrite03.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2017 Carlo Marcelo Arenas Belon <[email protected]>
4  * Copyright (c) 2018 Cyril Hrubis <[email protected]>
5  */
6 
7 /*\
8  * [Description]
9  *
10  * Tests for a special case NULL buffer with size 0 is expected to return 0.
11  */
12 
13 #include <errno.h>
14 #include "tst_test.h"
15 
16 static int fd;
17 
verify_pwrite(void)18 static void verify_pwrite(void)
19 {
20 	TST_EXP_PASS(pwrite(fd, NULL, 0, 0), "pwrite(%d, NULL, 0) == 0", fd);
21 }
22 
setup(void)23 static void setup(void)
24 {
25 	fd = SAFE_OPEN("test_file", O_RDWR | O_CREAT, 0700);
26 }
27 
cleanup(void)28 static void cleanup(void)
29 {
30 	if (fd > 0)
31 		SAFE_CLOSE(fd);
32 }
33 
34 static struct tst_test test = {
35 	.setup = setup,
36 	.cleanup = cleanup,
37 	.test_all = verify_pwrite,
38 	.needs_tmpdir = 1,
39 };
40