This source file includes following definitions.
- test_unlink_func
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 static int
26 test_unlink_func (int (*func) (char const *name), bool print)
27 {
28
29 ASSERT (mkdir (BASE "dir", 0700) == 0);
30 ASSERT (close (creat (BASE "dir/file", 0600)) == 0);
31
32
33 errno = 0;
34 ASSERT (func ("") == -1);
35 ASSERT (errno == ENOENT);
36 errno = 0;
37 ASSERT (func (BASE "nosuch") == -1);
38 ASSERT (errno == ENOENT);
39 errno = 0;
40 ASSERT (func (BASE "nosuch/") == -1);
41 ASSERT (errno == ENOENT);
42
43
44
45
46 if (cannot_unlink_dir ())
47 {
48 ASSERT (func (".") == -1);
49 ASSERT (func ("..") == -1);
50 ASSERT (func ("/") == -1);
51 ASSERT (func (BASE "dir") == -1);
52 ASSERT (mkdir (BASE "dir1", 0700) == 0);
53 ASSERT (func (BASE "dir1") == -1);
54 ASSERT (rmdir (BASE "dir1") == 0);
55 }
56 errno = 0;
57 ASSERT (func (BASE "dir/file/") == -1);
58 ASSERT (errno == ENOTDIR);
59
60
61
62
63 if (symlink (BASE "dir", BASE "link") != 0)
64 {
65 ASSERT (func (BASE "dir/file") == 0);
66 ASSERT (rmdir (BASE "dir") == 0);
67 if (print)
68 fputs ("skipping test: symlinks not supported on this file system\n",
69 stderr);
70 return 77;
71 }
72 if (cannot_unlink_dir ())
73 ASSERT (func (BASE "link/") == -1);
74 ASSERT (func (BASE "link") == 0);
75 ASSERT (symlink (BASE "dir/file", BASE "link") == 0);
76 errno = 0;
77 ASSERT (func (BASE "link/") == -1);
78 ASSERT (errno == ENOTDIR);
79
80
81 ASSERT (func (BASE "link") == 0);
82 ASSERT (func (BASE "dir/file") == 0);
83 ASSERT (rmdir (BASE "dir") == 0);
84
85 return 0;
86 }