]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
stat-util: add _at() variant for files_same()
authorLennart Poettering <lennart@poettering.net>
Mon, 15 May 2023 19:20:17 +0000 (21:20 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 19 May 2023 15:41:08 +0000 (17:41 +0200)
src/basic/stat-util.c
src/basic/stat-util.h

index 335daca2345217443e4ca31f81688c7ea79469c8..20152fbe2b48fbc442c13f2314777dc5d625b608 100644 (file)
@@ -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);
index e6b84d215e0afca050b91743f581f645cb1c67df..25f915f558b524681b381a08abb7c0a3791069a0 100644 (file)
@@ -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. */