• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) International Business Machines  Corp., 2001
4  */
5 
6 /*\
7  * [Description]
8  *
9  * Testcase to test whether chdir(2) sets errno correctly.
10  */
11 
12 #include <errno.h>
13 #include "tst_test.h"
14 
15 static char long_dir[] = "abcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyz";
16 static char noexist_dir[] = "noexistdir";
17 
18 static struct tcase {
19 	char *dir;
20 	int exp_errno;
21 } tcases[] = {
22 	{long_dir, ENAMETOOLONG},
23 	{noexist_dir, ENOENT},
24 	{0, EFAULT}, // bad_addr
25 };
26 
verify_chdir(unsigned int i)27 static void verify_chdir(unsigned int i)
28 {
29 	TST_EXP_FAIL(chdir(tcases[i].dir), tcases[i].exp_errno, "chdir()");
30 }
31 
setup(void)32 static void setup(void)
33 {
34 	tcases[2].dir = tst_get_bad_addr(NULL);
35 }
36 
37 static struct tst_test test = {
38 	.needs_tmpdir = 1,
39 	.test = verify_chdir,
40 	.tcnt = ARRAY_SIZE(tcases),
41 	.setup = setup,
42 };
43