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