summaryrefslogtreecommitdiff
path: root/lib/tempfile.c
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2018-06-08 10:09:00 +0100
committerColin Watson <cjwatson@debian.org>2018-06-08 10:09:00 +0100
commit7ef8e4fffc09c568b158fe8015345b1ae4986148 (patch)
tree48ef4f6a428bd9d916ef8e14e6ee205d29888752 /lib/tempfile.c
parent32995639aa2ee83a07165a82a045b3cb60924dff (diff)
Define an access(2) wrapper with clearer semantics
As usual for system calls, access(2) returns zero on success. However, I generally think of it as "can we access this file in this way", where boolean semantics would be more convenient, and find it too easy to invert logic by accident when using the system call directly. Define a CAN_ACCESS wrapper with boolean semantics. * include/manconfig.h.in (CAN_ACCESS): New macro. * lib/tempfile.c (path_search): Use CAN_ACCESS. * src/catman.c (check_access): Likewise. * src/filenames.c (make_filename): Likewise. * src/man.c (make_roff_command, display): Likewise. * src/ult_src.c (find_include): Likewise. * src/whatis.c (use_grep): Likewise.
Diffstat (limited to 'lib/tempfile.c')
-rw-r--r--lib/tempfile.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/tempfile.c b/lib/tempfile.c
index 3a9678d4..91ee0fb1 100644
--- a/lib/tempfile.c
+++ b/lib/tempfile.c
@@ -38,24 +38,24 @@ static const char *path_search (void)
if (getuid () == geteuid () && getgid () == getegid ()) {
dir = getenv ("TMPDIR");
- if (!dir || access (dir, W_OK) == -1)
+ if (!dir || !CAN_ACCESS (dir, W_OK))
dir = NULL;
if (!dir) {
dir = getenv ("TMP");
- if (!dir || access (dir, W_OK) == -1)
+ if (!dir || !CAN_ACCESS (dir, W_OK))
dir = NULL;
}
}
#ifdef P_tmpdir
if (!dir) {
dir = P_tmpdir;
- if (!dir || access (dir, W_OK) == -1)
+ if (!dir || !CAN_ACCESS (dir, W_OK))
dir = NULL;
}
#endif
if (!dir) {
dir = "/tmp";
- if (access (dir, W_OK) == -1)
+ if (!CAN_ACCESS (dir, W_OK))
dir = NULL;
}