1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) 2017 Carlo Marcelo Arenas Belon <carlo@gmail.com>
4 * Copyright (c) 2018 Cyril Hrubis <chrubis@suse.cz>
5 */
6 /*
7 * Tests for a special case NULL buffer with size 0 is expected to return 0.
8 */
9
10 #include <errno.h>
11 #include "tst_test.h"
12
13 static int fd;
14
verify_write(void)15 static void verify_write(void)
16 {
17 TEST(write(fd, NULL, 0));
18
19 if (TST_RET != 0) {
20 tst_res(TFAIL | TTERRNO,
21 "write() should have succeeded with ret=0");
22 return;
23 }
24
25 tst_res(TPASS, "write(fd, NULL, 0) == 0");
26 }
27
setup(void)28 static void setup(void)
29 {
30 fd = SAFE_OPEN("test_file", O_RDWR | O_CREAT, 0700);
31 }
32
cleanup(void)33 static void cleanup(void)
34 {
35 if (fd > 0)
36 SAFE_CLOSE(fd);
37 }
38
39 static struct tst_test test = {
40 .setup = setup,
41 .cleanup = cleanup,
42 .test_all = verify_write,
43 .needs_tmpdir = 1,
44 };
45