1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) 2017 Carlo Marcelo Arenas Belon <carlo@gmail.com> 4f08c3bdfSopenharmony_ci * Copyright (c) 2018 Cyril Hrubis <chrubis@suse.cz> 5f08c3bdfSopenharmony_ci * Copyright (c) Linux Test Project, 2003-2023 6f08c3bdfSopenharmony_ci */ 7f08c3bdfSopenharmony_ci 8f08c3bdfSopenharmony_ci/*\ 9f08c3bdfSopenharmony_ci * [Description] 10f08c3bdfSopenharmony_ci * 11f08c3bdfSopenharmony_ci * Tests for a special case NULL buffer with size 0 is expected to return 0. 12f08c3bdfSopenharmony_ci */ 13f08c3bdfSopenharmony_ci 14f08c3bdfSopenharmony_ci#include "tst_test.h" 15f08c3bdfSopenharmony_ci 16f08c3bdfSopenharmony_cistatic int fd; 17f08c3bdfSopenharmony_ci 18f08c3bdfSopenharmony_cistatic void verify_write(void) 19f08c3bdfSopenharmony_ci{ 20f08c3bdfSopenharmony_ci TST_EXP_POSITIVE(write(fd, NULL, 0)); 21f08c3bdfSopenharmony_ci 22f08c3bdfSopenharmony_ci TST_EXP_EXPR(TST_RET == 0, "write(fd, NULL, %ld) == %d", TST_RET, 0); 23f08c3bdfSopenharmony_ci} 24f08c3bdfSopenharmony_ci 25f08c3bdfSopenharmony_cistatic void setup(void) 26f08c3bdfSopenharmony_ci{ 27f08c3bdfSopenharmony_ci fd = SAFE_OPEN("test_file", O_RDWR | O_CREAT, 0700); 28f08c3bdfSopenharmony_ci} 29f08c3bdfSopenharmony_ci 30f08c3bdfSopenharmony_cistatic void cleanup(void) 31f08c3bdfSopenharmony_ci{ 32f08c3bdfSopenharmony_ci if (fd > 0) 33f08c3bdfSopenharmony_ci SAFE_CLOSE(fd); 34f08c3bdfSopenharmony_ci} 35f08c3bdfSopenharmony_ci 36f08c3bdfSopenharmony_cistatic struct tst_test test = { 37f08c3bdfSopenharmony_ci .setup = setup, 38f08c3bdfSopenharmony_ci .cleanup = cleanup, 39f08c3bdfSopenharmony_ci .test_all = verify_write, 40f08c3bdfSopenharmony_ci .needs_tmpdir = 1, 41f08c3bdfSopenharmony_ci}; 42