This source file includes following definitions.
- test_stat_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_stat_func (int (*func) (char const *, struct stat *), bool print)
27 {
28 struct stat st1;
29 struct stat st2;
30 char *cwd = getcwd (NULL, 0);
31
32 ASSERT (cwd);
33 ASSERT (func (".", &st1) == 0);
34 ASSERT (func ("./", &st2) == 0);
35 #if !(defined _WIN32 && !defined __CYGWIN__ && !_GL_WINDOWS_STAT_INODES)
36 ASSERT (SAME_INODE (st1, st2));
37 #endif
38 ASSERT (func (cwd, &st2) == 0);
39 #if !(defined _WIN32 && !defined __CYGWIN__ && !_GL_WINDOWS_STAT_INODES)
40 ASSERT (SAME_INODE (st1, st2));
41 #endif
42 ASSERT (func ("/", &st1) == 0);
43 ASSERT (func ("///", &st2) == 0);
44 #if !(defined _WIN32 && !defined __CYGWIN__ && !_GL_WINDOWS_STAT_INODES)
45 ASSERT (SAME_INODE (st1, st2));
46 #endif
47
48 errno = 0;
49 ASSERT (func ("", &st1) == -1);
50 ASSERT (errno == ENOENT);
51 errno = 0;
52 ASSERT (func ("nosuch", &st1) == -1);
53 ASSERT (errno == ENOENT);
54 errno = 0;
55 ASSERT (func ("nosuch/", &st1) == -1);
56 ASSERT (errno == ENOENT);
57
58 ASSERT (close (creat (BASE "file", 0600)) == 0);
59 ASSERT (func (BASE "file", &st1) == 0);
60 errno = 0;
61 ASSERT (func (BASE "file/", &st1) == -1);
62 ASSERT (errno == ENOTDIR);
63
64
65
66
67
68
69
70
71 if (symlink (".", BASE "link1") != 0)
72 {
73 ASSERT (unlink (BASE "file") == 0);
74 if (print)
75 fputs ("skipping test: symlinks not supported on this file system\n",
76 stderr);
77 return 77;
78 }
79 ASSERT (symlink (BASE "file", BASE "link2") == 0);
80 ASSERT (symlink (BASE "nosuch", BASE "link3") == 0);
81 ASSERT (symlink (BASE "link4", BASE "link4") == 0);
82
83 ASSERT (func (BASE "link1/", &st1) == 0);
84 ASSERT (S_ISDIR (st1.st_mode));
85
86 errno = 0;
87 ASSERT (func (BASE "link2/", &st1) == -1);
88 ASSERT (errno == ENOTDIR);
89
90 errno = 0;
91 ASSERT (func (BASE "link3/", &st1) == -1);
92 ASSERT (errno == ENOENT);
93
94 errno = 0;
95 ASSERT (func (BASE "link4/", &st1) == -1);
96 ASSERT (errno == ELOOP);
97
98
99 ASSERT (unlink (BASE "file") == 0);
100 ASSERT (unlink (BASE "link1") == 0);
101 ASSERT (unlink (BASE "link2") == 0);
102 ASSERT (unlink (BASE "link3") == 0);
103 ASSERT (unlink (BASE "link4") == 0);
104 free (cwd);
105
106 return 0;
107 }