]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fs-util: make laccess() macro follow our usual error propagation
authorLennart Poettering <lennart@poettering.net>
Fri, 15 Jan 2021 13:54:11 +0000 (14:54 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 15 Jan 2021 19:14:10 +0000 (19:14 +0000)
Functions defined by us are supposed to return negative errno-style
errors on errors. laccess() is for access() what lstat() is for stat(),
but defined by us as a macro. This led to some confusion regarding error
handling.

Let's return a negative errno code just in case. This means callers can
it use either way: like access(), i.e. checking for a negative return
value + looking at errno, or like our own code, i.e. using the negative
errno code it returns.

src/basic/fs-util.h

index 9a39473567f88b938d2e07892f2d9ee8ac030155..13b68729422cfd87c0076965d0eb4c340930bfc4 100644 (file)
@@ -43,7 +43,8 @@ int futimens_opath(int fd, const struct timespec ts[2]);
 int fd_warn_permissions(const char *path, int fd);
 int stat_warn_permissions(const char *path, const struct stat *st);
 
-#define laccess(path, mode) faccessat(AT_FDCWD, (path), (mode), AT_SYMLINK_NOFOLLOW)
+#define laccess(path, mode)                                             \
+        (faccessat(AT_FDCWD, (path), (mode), AT_SYMLINK_NOFOLLOW) < 0 ? -errno : 0)
 
 int touch_file(const char *path, bool parents, usec_t stamp, uid_t uid, gid_t gid, mode_t mode);
 int touch(const char *path);