diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-03-22 17:04:29 +0100 |
---|---|---|
committer | Sven Eden <yamakuzure@gmx.net> | 2018-08-24 16:47:08 +0200 |
commit | f2e5755be31573b10852c9e8bd97a9881e925758 (patch) | |
tree | 80ca4f27ea58b3d71dd6a3bbc91f6ffe152fa2a5 /src/basic/fs-util.c | |
parent | c280e28425e1f9a55a2bdbe3c988a56280c8bfdb (diff) |
macro: introduce new TAKE_FD() macro
This is similar to TAKE_PTR() but operates on file descriptors, and thus
assigns -1 to the fd parameter after returning it.
Removes 60 lines from our codebase. Pretty good too I think.
Diffstat (limited to 'src/basic/fs-util.c')
-rw-r--r-- | src/basic/fs-util.c | 13 |
1 files changed, 3 insertions, 10 deletions
diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index f5764454f..12255fe0c 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -745,8 +745,7 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags, } safe_close(fd); - fd = fd_parent; - fd_parent = -1; + fd = TAKE_FD(fd_parent); continue; } @@ -864,8 +863,7 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags, /* And iterate again, but go one directory further down. */ safe_close(fd); - fd = child; - child = -1; + fd = TAKE_FD(child); } if (!done) { @@ -879,16 +877,11 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags, *ret = TAKE_PTR(done); if (flags & CHASE_OPEN) { - int q; - /* Return the O_PATH fd we currently are looking to the caller. It can translate it to a proper fd by * opening /proc/self/fd/xyz. */ assert(fd >= 0); - q = fd; - fd = -1; - - return q; + return TAKE_FD(fd); } return exists; |