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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15702
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
15702
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 #include <config.h>
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <unistd.h>
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include "signature.h"
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 SIGNATURE_CHECK (faccessat, int, (int, const char *, int, int));
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include <errno.h>
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #include <fcntl.h>
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 #include "macros.h"
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 int
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 main (void)
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 {
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 /* Test behaviour for invalid file descriptors. */
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 {
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 errno = 0;
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 ASSERT (faccessat (-1, "foo", F_OK, 0) == -1);
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 ASSERT (errno == EBADF);
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 }
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 errno = 0;
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 ASSERT (faccessat (99, "foo", F_OK, 0) == -1);
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 ASSERT (errno == EBADF);
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 }
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 return 0;
e52fd8710d18 Tests for module 'faccessat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 }