Mercurial > hg > octave-lojdl > gnulib-hg
annotate tests/test-stat.h @ 14079:97fc9a21a8fb
maint: update almost all copyright ranges to include 2011
Run the new "make update-copyright" rule.
author | Jim Meyering <meyering@redhat.com> |
---|---|
date | Sat, 01 Jan 2011 20:17:23 +0100 |
parents | c2cbabec01dd |
children | 8f229ae087b4 |
rev | line source |
---|---|
12042
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
1 /* Tests of stat. |
14079
97fc9a21a8fb
maint: update almost all copyright ranges to include 2011
Jim Meyering <meyering@redhat.com>
parents:
12559
diff
changeset
|
2 Copyright (C) 2009-2011 Free Software Foundation, Inc. |
12042
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
3 |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
5 it under the terms of the GNU General Public License as published by |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
6 the Free Software Foundation; either version 3 of the License, or |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
7 (at your option) any later version. |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
8 |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
12 GNU General Public License for more details. |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
13 |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
14 You should have received a copy of the GNU General Public License |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
16 |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
17 /* Written by Eric Blake <ebb9@byu.net>, 2009. */ |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
18 |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
19 /* This file is designed to test both stat(n,buf) and |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
20 fstatat(AT_FDCWD,n,buf,0). FUNC is the function to test. Assumes |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
21 that BASE and ASSERT are already defined, and that appropriate |
12258 | 22 headers are already included. If PRINT, warn before skipping |
23 symlink tests with status 77. */ | |
12042
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
24 |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
25 static int |
12258 | 26 test_stat_func (int (*func) (char const *, struct stat *), bool print) |
12042
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
27 { |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
28 struct stat st1; |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
29 struct stat st2; |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
30 char cwd[PATH_MAX]; |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
31 |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
32 ASSERT (getcwd (cwd, PATH_MAX) == cwd); |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
33 ASSERT (func (".", &st1) == 0); |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
34 ASSERT (func ("./", &st2) == 0); |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
35 ASSERT (SAME_INODE (st1, st2)); |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
36 ASSERT (func (cwd, &st2) == 0); |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
37 ASSERT (SAME_INODE (st1, st2)); |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
38 ASSERT (func ("/", &st1) == 0); |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
39 ASSERT (func ("///", &st2) == 0); |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
40 ASSERT (SAME_INODE (st1, st2)); |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
41 |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
42 errno = 0; |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
43 ASSERT (func ("", &st1) == -1); |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
44 ASSERT (errno == ENOENT); |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
45 errno = 0; |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
46 ASSERT (func ("nosuch", &st1) == -1); |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
47 ASSERT (errno == ENOENT); |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
48 errno = 0; |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
49 ASSERT (func ("nosuch/", &st1) == -1); |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
50 ASSERT (errno == ENOENT); |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
51 |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
52 ASSERT (close (creat (BASE "file", 0600)) == 0); |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
53 ASSERT (func (BASE "file", &st1) == 0); |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
54 errno = 0; |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
55 ASSERT (func (BASE "file/", &st1) == -1); |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
56 ASSERT (errno == ENOTDIR); |
12258 | 57 |
58 /* Now for some symlink tests, where supported. We set up: | |
59 link1 -> directory | |
60 link2 -> file | |
61 link3 -> dangling | |
62 link4 -> loop | |
63 then test behavior with trailing slash. | |
64 */ | |
65 if (symlink (".", BASE "link1") != 0) | |
66 { | |
67 ASSERT (unlink (BASE "file") == 0); | |
68 if (print) | |
69 fputs ("skipping test: symlinks not supported on this file system\n", | |
70 stderr); | |
71 return 77; | |
72 } | |
73 ASSERT (symlink (BASE "file", BASE "link2") == 0); | |
74 ASSERT (symlink (BASE "nosuch", BASE "link3") == 0); | |
75 ASSERT (symlink (BASE "link4", BASE "link4") == 0); | |
76 | |
77 ASSERT (func (BASE "link1/", &st1) == 0); | |
78 ASSERT (S_ISDIR (st1.st_mode)); | |
79 | |
80 errno = 0; | |
81 ASSERT (func (BASE "link2/", &st1) == -1); | |
82 ASSERT (errno == ENOTDIR); | |
83 | |
84 errno = 0; | |
85 ASSERT (func (BASE "link3/", &st1) == -1); | |
86 ASSERT (errno == ENOENT); | |
87 | |
88 errno = 0; | |
89 ASSERT (func (BASE "link4/", &st1) == -1); | |
90 ASSERT (errno == ELOOP); | |
91 | |
92 /* Cleanup. */ | |
12042
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
93 ASSERT (unlink (BASE "file") == 0); |
12258 | 94 ASSERT (unlink (BASE "link1") == 0); |
95 ASSERT (unlink (BASE "link2") == 0); | |
96 ASSERT (unlink (BASE "link3") == 0); | |
97 ASSERT (unlink (BASE "link4") == 0); | |
12042
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
98 |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
99 return 0; |
42d53e82a460
test-fstatat: new test, to expose Solaris 9 bugs
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
100 } |