From: Krzesimir Nowak Date: Thu, 11 Apr 2024 12:38:19 +0000 (+0200) Subject: path-util: Add a helper for checking paths X-Git-Tag: v256-rc1~86^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=581d8a14705771f8661c7b41a8f07ead594f0d40;p=thirdparty%2Fsystemd.git path-util: Add a helper for checking paths The difference with the already existing path_equal_or_inode_same function is that the new one does not swallow errors. --- diff --git a/src/basic/path-util.c b/src/basic/path-util.c index 4d335c64eed..16b13ed628a 100644 --- a/src/basic/path-util.c +++ b/src/basic/path-util.c @@ -525,6 +525,18 @@ int path_compare_filename(const char *a, const char *b) { return strcmp(fa, fb); } +int path_equal_or_inode_same_full(const char *a, const char *b, int flags) { + /* Returns true if paths are of the same entry, false if not, <0 on error. */ + + if (path_equal(a, b)) + return 1; + + if (!a || !b) + return 0; + + return inode_same(a, b, flags); +} + char* path_extend_internal(char **x, ...) { size_t sz, old_sz; char *q, *nx; diff --git a/src/basic/path-util.h b/src/basic/path-util.h index 6d88c54d7f0..368e0001217 100644 --- a/src/basic/path-util.h +++ b/src/basic/path-util.h @@ -68,8 +68,9 @@ static inline bool path_equal_filename(const char *a, const char *b) { return path_compare_filename(a, b) == 0; } +int path_equal_or_inode_same_full(const char *a, const char *b, int flags); static inline bool path_equal_or_inode_same(const char *a, const char *b, int flags) { - return path_equal(a, b) || inode_same(a, b, flags) > 0; + return path_equal_or_inode_same_full(a, b, flags) > 0; } char* path_extend_internal(char **x, ...);