From: Lennart Poettering Date: Mon, 15 May 2023 19:20:17 +0000 (+0200) Subject: stat-util: add _at() variant for files_same() X-Git-Tag: v254-rc1~435^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=676ade310a7bb17b9fb0deaefa5e7c5d1c9ef8b4;p=thirdparty%2Fsystemd.git stat-util: add _at() variant for files_same() --- diff --git a/src/basic/stat-util.c b/src/basic/stat-util.c index 335daca2345..20152fbe2b4 100644 --- a/src/basic/stat-util.c +++ b/src/basic/stat-util.c @@ -183,16 +183,18 @@ int path_is_read_only_fs(const char *path) { return fd_is_read_only_fs(fd); } -int files_same(const char *filea, const char *fileb, int flags) { +int files_same_at(int fda, const char *filea, int fdb, const char *fileb, int flags) { struct stat a, b; + assert(fda >= 0 || fda == AT_FDCWD); assert(filea); + assert(fdb >= 0 || fdb == AT_FDCWD); assert(fileb); - if (fstatat(AT_FDCWD, filea, &a, flags) < 0) + if (fstatat(fda, filea, &a, flags) < 0) return log_debug_errno(errno, "Cannot stat %s: %m", filea); - if (fstatat(AT_FDCWD, fileb, &b, flags) < 0) + if (fstatat(fdb, fileb, &b, flags) < 0) return log_debug_errno(errno, "Cannot stat %s: %m", fileb); return stat_inode_same(&a, &b); diff --git a/src/basic/stat-util.h b/src/basic/stat-util.h index e6b84d215e0..25f915f558b 100644 --- a/src/basic/stat-util.h +++ b/src/basic/stat-util.h @@ -37,7 +37,11 @@ static inline int null_or_empty_path(const char *fn) { int path_is_read_only_fs(const char *path); -int files_same(const char *filea, const char *fileb, int flags); +int files_same_at(int fda, const char *filea, int fdb, const char *fileb, int flags); + +static inline int files_same(const char *filea, const char *fileb, int flags) { + return files_same_at(AT_FDCWD, filea, AT_FDCWD, fileb, flags); +} /* The .f_type field of struct statfs is really weird defined on * different archs. Let's give its type a name. */