Mercurial > gnulib
annotate tests/test-faccessat.c @ 40057:b06060465f09
maint: Run 'make update-copyright'
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Tue, 01 Jan 2019 00:25:11 +0100 |
parents | 10eb9086bea0 |
children |
rev | line source |
---|---|
15702 | 1 /* Test checking user's permissions for a file. |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
2 Copyright (C) 2011-2019 Free Software Foundation, Inc. |
15702 | 3 |
4 This program is free software: you can redistribute it and/or modify | |
5 it under the terms of the GNU General Public License as published by | |
6 the Free Software Foundation; either version 3 of the License, or | |
7 (at your option) any later version. | |
8 | |
9 This program is distributed in the hope that it will be useful, | |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 GNU General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
19190 | 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
15702 | 16 |
17 #include <config.h> | |
18 | |
19 #include <unistd.h> | |
20 | |
21 #include "signature.h" | |
22 SIGNATURE_CHECK (faccessat, int, (int, const char *, int, int)); | |
23 | |
24 #include <errno.h> | |
25 #include <fcntl.h> | |
26 | |
27 #include "macros.h" | |
28 | |
19456
334c91011c45
test-faccessat.c: correct BASE definition to avoid parallel test failure
Jim Meyering <meyering@fb.com>
parents:
19437
diff
changeset
|
29 #define BASE "test-faccessat.t" |
19437
23bf293630c0
faccessat: port to macOS (Bug#29231)
Paul Eggert <eggert@cs.ucla.edu>
parents:
19190
diff
changeset
|
30 |
15702 | 31 int |
32 main (void) | |
33 { | |
34 /* Test behaviour for invalid file descriptors. */ | |
35 { | |
36 errno = 0; | |
37 ASSERT (faccessat (-1, "foo", F_OK, 0) == -1); | |
38 ASSERT (errno == EBADF); | |
39 } | |
40 { | |
17292
3a09cc104f4c
tests: don't assume fd 99 is closed
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
41 close (99); |
15702 | 42 errno = 0; |
43 ASSERT (faccessat (99, "foo", F_OK, 0) == -1); | |
44 ASSERT (errno == EBADF); | |
45 } | |
46 | |
19437
23bf293630c0
faccessat: port to macOS (Bug#29231)
Paul Eggert <eggert@cs.ucla.edu>
parents:
19190
diff
changeset
|
47 /* Test behavior with trailing slash. */ |
19466
cf3b6a20c6bf
test-faccessat.c: avoid test failure if prior partial run
Pádraig Brady <P@draigBrady.com>
parents:
19465
diff
changeset
|
48 unlink (BASE "file"); |
19437
23bf293630c0
faccessat: port to macOS (Bug#29231)
Paul Eggert <eggert@cs.ucla.edu>
parents:
19190
diff
changeset
|
49 ASSERT (faccessat (AT_FDCWD, ".", X_OK, 0) == 0); |
23bf293630c0
faccessat: port to macOS (Bug#29231)
Paul Eggert <eggert@cs.ucla.edu>
parents:
19190
diff
changeset
|
50 ASSERT (faccessat (AT_FDCWD, "./", X_OK, 0) == 0); |
23bf293630c0
faccessat: port to macOS (Bug#29231)
Paul Eggert <eggert@cs.ucla.edu>
parents:
19190
diff
changeset
|
51 ASSERT (close (open (BASE "file", O_CREAT | O_WRONLY, 0)) == 0); |
23bf293630c0
faccessat: port to macOS (Bug#29231)
Paul Eggert <eggert@cs.ucla.edu>
parents:
19190
diff
changeset
|
52 ASSERT (faccessat (AT_FDCWD, BASE "file", F_OK, 0) == 0); |
23bf293630c0
faccessat: port to macOS (Bug#29231)
Paul Eggert <eggert@cs.ucla.edu>
parents:
19190
diff
changeset
|
53 ASSERT (faccessat (AT_FDCWD, BASE "file/", F_OK, 0) != 0); |
23bf293630c0
faccessat: port to macOS (Bug#29231)
Paul Eggert <eggert@cs.ucla.edu>
parents:
19190
diff
changeset
|
54 unlink (BASE "link1"); |
23bf293630c0
faccessat: port to macOS (Bug#29231)
Paul Eggert <eggert@cs.ucla.edu>
parents:
19190
diff
changeset
|
55 if (symlink (".", BASE "link1") == 0) |
23bf293630c0
faccessat: port to macOS (Bug#29231)
Paul Eggert <eggert@cs.ucla.edu>
parents:
19190
diff
changeset
|
56 { |
23bf293630c0
faccessat: port to macOS (Bug#29231)
Paul Eggert <eggert@cs.ucla.edu>
parents:
19190
diff
changeset
|
57 ASSERT (faccessat (AT_FDCWD, BASE "link1", X_OK, 0) == 0); |
23bf293630c0
faccessat: port to macOS (Bug#29231)
Paul Eggert <eggert@cs.ucla.edu>
parents:
19190
diff
changeset
|
58 ASSERT (faccessat (AT_FDCWD, BASE "link1/", X_OK, 0) == 0); |
23bf293630c0
faccessat: port to macOS (Bug#29231)
Paul Eggert <eggert@cs.ucla.edu>
parents:
19190
diff
changeset
|
59 |
23bf293630c0
faccessat: port to macOS (Bug#29231)
Paul Eggert <eggert@cs.ucla.edu>
parents:
19190
diff
changeset
|
60 unlink (BASE "link2"); |
23bf293630c0
faccessat: port to macOS (Bug#29231)
Paul Eggert <eggert@cs.ucla.edu>
parents:
19190
diff
changeset
|
61 ASSERT (symlink (BASE "file", BASE "link2") == 0); |
23bf293630c0
faccessat: port to macOS (Bug#29231)
Paul Eggert <eggert@cs.ucla.edu>
parents:
19190
diff
changeset
|
62 ASSERT (faccessat (AT_FDCWD, BASE "link2", F_OK, 0) == 0); |
23bf293630c0
faccessat: port to macOS (Bug#29231)
Paul Eggert <eggert@cs.ucla.edu>
parents:
19190
diff
changeset
|
63 ASSERT (faccessat (AT_FDCWD, BASE "link2/", F_OK, 0) != 0); |
23bf293630c0
faccessat: port to macOS (Bug#29231)
Paul Eggert <eggert@cs.ucla.edu>
parents:
19190
diff
changeset
|
64 unlink (BASE "link2"); |
23bf293630c0
faccessat: port to macOS (Bug#29231)
Paul Eggert <eggert@cs.ucla.edu>
parents:
19190
diff
changeset
|
65 |
23bf293630c0
faccessat: port to macOS (Bug#29231)
Paul Eggert <eggert@cs.ucla.edu>
parents:
19190
diff
changeset
|
66 unlink (BASE "link3"); |
23bf293630c0
faccessat: port to macOS (Bug#29231)
Paul Eggert <eggert@cs.ucla.edu>
parents:
19190
diff
changeset
|
67 ASSERT (symlink (BASE "no-such-file", BASE "link3") == 0); |
23bf293630c0
faccessat: port to macOS (Bug#29231)
Paul Eggert <eggert@cs.ucla.edu>
parents:
19190
diff
changeset
|
68 ASSERT (faccessat (AT_FDCWD, BASE "link3", F_OK, 0) != 0); |
23bf293630c0
faccessat: port to macOS (Bug#29231)
Paul Eggert <eggert@cs.ucla.edu>
parents:
19190
diff
changeset
|
69 ASSERT (faccessat (AT_FDCWD, BASE "link3/", F_OK, 0) != 0); |
23bf293630c0
faccessat: port to macOS (Bug#29231)
Paul Eggert <eggert@cs.ucla.edu>
parents:
19190
diff
changeset
|
70 unlink (BASE "link3"); |
23bf293630c0
faccessat: port to macOS (Bug#29231)
Paul Eggert <eggert@cs.ucla.edu>
parents:
19190
diff
changeset
|
71 } |
23bf293630c0
faccessat: port to macOS (Bug#29231)
Paul Eggert <eggert@cs.ucla.edu>
parents:
19190
diff
changeset
|
72 unlink (BASE "link1"); |
19465
eacb76c279af
test-faccessat.c: unlink temp file to avoid subsequent test failure
Pádraig Brady <P@draigBrady.com>
parents:
19456
diff
changeset
|
73 unlink (BASE "file"); |
19437
23bf293630c0
faccessat: port to macOS (Bug#29231)
Paul Eggert <eggert@cs.ucla.edu>
parents:
19190
diff
changeset
|
74 |
15702 | 75 return 0; |
76 } |