xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/fchdir/fchdir01.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker  *   Copyright (c) International Business Machines  Corp., 2001
4*49cdfc7eSAndroid Build Coastguard Worker  */
5*49cdfc7eSAndroid Build Coastguard Worker 
6*49cdfc7eSAndroid Build Coastguard Worker /*
7*49cdfc7eSAndroid Build Coastguard Worker  * DESCRIPTION
8*49cdfc7eSAndroid Build Coastguard Worker  *	fchdir01 - create a directory and cd into it.
9*49cdfc7eSAndroid Build Coastguard Worker  */
10*49cdfc7eSAndroid Build Coastguard Worker 
11*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
12*49cdfc7eSAndroid Build Coastguard Worker 
13*49cdfc7eSAndroid Build Coastguard Worker static int fd;
14*49cdfc7eSAndroid Build Coastguard Worker static const char *TEST_DIR = "alpha";
15*49cdfc7eSAndroid Build Coastguard Worker 
16*49cdfc7eSAndroid Build Coastguard Worker #define MODES	S_IRWXU
17*49cdfc7eSAndroid Build Coastguard Worker 
verify_fchdir(void)18*49cdfc7eSAndroid Build Coastguard Worker static void verify_fchdir(void)
19*49cdfc7eSAndroid Build Coastguard Worker {
20*49cdfc7eSAndroid Build Coastguard Worker 	TST_EXP_PASS(fchdir(fd));
21*49cdfc7eSAndroid Build Coastguard Worker }
22*49cdfc7eSAndroid Build Coastguard Worker 
setup(void)23*49cdfc7eSAndroid Build Coastguard Worker static void setup(void)
24*49cdfc7eSAndroid Build Coastguard Worker {
25*49cdfc7eSAndroid Build Coastguard Worker 	SAFE_MKDIR(TEST_DIR, MODES);
26*49cdfc7eSAndroid Build Coastguard Worker 	fd = SAFE_OPEN(TEST_DIR, O_RDONLY);
27*49cdfc7eSAndroid Build Coastguard Worker }
28*49cdfc7eSAndroid Build Coastguard Worker 
cleanup(void)29*49cdfc7eSAndroid Build Coastguard Worker static void cleanup(void)
30*49cdfc7eSAndroid Build Coastguard Worker {
31*49cdfc7eSAndroid Build Coastguard Worker 	SAFE_CLOSE(fd);
32*49cdfc7eSAndroid Build Coastguard Worker }
33*49cdfc7eSAndroid Build Coastguard Worker 
34*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
35*49cdfc7eSAndroid Build Coastguard Worker 	.test_all = verify_fchdir,
36*49cdfc7eSAndroid Build Coastguard Worker 	.setup = setup,
37*49cdfc7eSAndroid Build Coastguard Worker 	.cleanup = cleanup,
38*49cdfc7eSAndroid Build Coastguard Worker 	.needs_tmpdir = 1,
39*49cdfc7eSAndroid Build Coastguard Worker };
40