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 * Copyright (c) Linux Test Project, 2003-2023 6 */ 7 8/*\ 9 * [Description] 10 * 11 * Tests for a special case NULL buffer with size 0 is expected to return 0. 12 */ 13 14#include "tst_test.h" 15 16static int fd; 17 18static void verify_write(void) 19{ 20 TST_EXP_POSITIVE(write(fd, NULL, 0)); 21 22 TST_EXP_EXPR(TST_RET == 0, "write(fd, NULL, %ld) == %d", TST_RET, 0); 23} 24 25static void setup(void) 26{ 27 fd = SAFE_OPEN("test_file", O_RDWR | O_CREAT, 0700); 28} 29 30static void cleanup(void) 31{ 32 if (fd > 0) 33 SAFE_CLOSE(fd); 34} 35 36static struct tst_test test = { 37 .setup = setup, 38 .cleanup = cleanup, 39 .test_all = verify_write, 40 .needs_tmpdir = 1, 41}; 42