// otherwise false.
operator bool() const;
+ // Return whether this object refers to the same device and i-node as `other`
+ // does.
+ bool same_inode_as(const Stat& other) const;
+
// Return errno from the (l)stat call (0 if successful).
int error_number() const;
private:
struct stat m_stat;
int m_errno;
+
+ bool operator==(const Stat&) const;
+ bool operator!=(const Stat&) const;
};
inline Stat::Stat() : m_stat{}, m_errno(-1)
return m_errno == 0;
}
+inline bool
+Stat::same_inode_as(const Stat& other) const
+{
+ return device() == other.device() && inode() == other.inode();
+}
+
inline int
Stat::error_number() const
{
Equals("failed to stat does_not_exist: No such file or directory"));
}
+TEST_CASE("Same i-node as")
+{
+ Util::write_file("a", "");
+ Util::write_file("b", "");
+ auto a_stat = Stat::stat("a");
+ auto b_stat = Stat::stat("b");
+
+ CHECK(a_stat.same_inode_as(a_stat));
+#ifdef _WIN32 // no i-node concept
+ (void)b_stat;
+#else
+ CHECK(!a_stat.same_inode_as(b_stat));
+#endif
+
+ Util::write_file("a", "change size");
+ auto new_a_stat = Stat::stat("a");
+ CHECK(new_a_stat.same_inode_as(a_stat));
+}
+
TEST_CASE("Return values when file is missing")
{
auto stat = Stat::stat("does_not_exist");