xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/fcntl/fcntl08.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
4  * Authors: William Roske, Dave Fenner
5  * Copyright (c) 2014 Fujitsu Ltd.
6  * Copyright (c) Linux Test Project, 2005-2015
7  * Copyright (C) 2024 SUSE LLC Andrea Manzini <[email protected]>
8  */
9 
10 /*\
11  * [Description]
12  *
13  * Basic test for fcntl(2) using F_SETFL with flags O_NDELAY | O_APPEND | O_NONBLOCK.
14  */
15 
16 #include "lapi/fcntl.h"
17 #include "tst_test.h"
18 
19 static int fd;
20 
setup(void)21 static void setup(void)
22 {
23 	fd = SAFE_OPEN("testfile", O_RDWR | O_CREAT, 0700);
24 }
25 
cleanup(void)26 static void cleanup(void)
27 {
28 	if (fd > 0)
29 		SAFE_CLOSE(fd);
30 }
31 
run(void)32 static void run(void)
33 {
34 	TST_EXP_PASS(fcntl(fd, F_SETFL, O_NDELAY | O_APPEND | O_NONBLOCK));
35 }
36 
37 static struct tst_test test = {
38 	.test_all = run,
39 	.setup = setup,
40 	.cleanup = cleanup,
41 	.needs_tmpdir = 1,
42 };
43