Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
return move_ptr(buf);
}
+
+bool same_file_lax(int fda, int fdb)
+{
+ struct stat st_fda, st_fdb;
+
+
+ if (fda == fdb)
+ return true;
+
+ if (fstat(fda, &st_fda) < 0)
+ return false;
+
+ if (fstat(fdb, &st_fdb) < 0)
+ return false;
+
+ errno = EINVAL;
+ if ((st_fda.st_mode & S_IFMT) != (st_fdb.st_mode & S_IFMT))
+ return false;
+
+ errno = EINVAL;
+ return (st_fda.st_dev == st_fdb.st_dev) &&
+ (st_fda.st_ino == st_fdb.st_ino);
+}
__hidden extern ssize_t lxc_read_try_buf_at(int dfd, const char *path,
void *buf, size_t count);
+/*
+ * Check if two fds refer to the same file.
+ * The function is "lax" in so far, as it doesn't care whether fda and fdb have
+ * the same flags or whether they share the same device context when they refer
+ * to devices.
+ */
+__hidden extern bool same_file_lax(int fda, int fdb);
+
#endif /* __LXC_FILE_UTILS_H */