2 Copyright (C) 2019-2020 Free Software Foundation, Inc.
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.
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.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
21 #include "signature.h"
22 SIGNATURE_CHECK (access
, int, (const char *, int));
30 /* mingw and MSVC 9 lack geteuid, so setup a dummy value. */
32 # define geteuid() ROOT_UID
35 #define BASE "test-access.t"
40 /* Remove anything from prior partial run. */
43 chmod (BASE
"f2", 0600);
48 ASSERT (access (BASE
"f", R_OK
) == -1);
49 ASSERT (errno
== ENOENT
);
52 ASSERT (access (BASE
"f", W_OK
) == -1);
53 ASSERT (errno
== ENOENT
);
56 ASSERT (access (BASE
"f", X_OK
) == -1);
57 ASSERT (errno
== ENOENT
);
60 ASSERT (close (creat (BASE
"f1", 0700)) == 0);
62 ASSERT (access (BASE
"f1", R_OK
) == 0);
63 ASSERT (access (BASE
"f1", W_OK
) == 0);
64 ASSERT (access (BASE
"f1", X_OK
) == 0);
67 ASSERT (close (creat (BASE
"f2", 0600)) == 0);
68 ASSERT (chmod (BASE
"f2", 0400) == 0);
70 ASSERT (access (BASE
"f2", R_OK
) == 0);
72 if (geteuid () != ROOT_UID
)
75 ASSERT (access (BASE
"f2", W_OK
) == -1);
76 ASSERT (errno
== EACCES
);
79 #if defined _WIN32 && !defined __CYGWIN__
80 /* X_OK works like R_OK. */
81 ASSERT (access (BASE
"f2", X_OK
) == 0);
84 ASSERT (access (BASE
"f2", X_OK
) == -1);
85 ASSERT (errno
== EACCES
);
90 ASSERT (unlink (BASE
"f1") == 0);
91 ASSERT (chmod (BASE
"f2", 0600) == 0);
92 ASSERT (unlink (BASE
"f2") == 0);