#ifndef MSP_FS_STAT_H_
#define MSP_FS_STAT_H_
-#include <sys/stat.h>
+#include <string>
+#include <msp/time/timestamp.h>
#include "path.h"
namespace Msp {
namespace FS {
-/** Gets information about a file. Returns 0 on success or -1 on error. This
-version can be used to check for file existence and get information in one
-call. */
-int stat(const Path &fn, struct stat &st);
+enum FileType
+{
+ UNKNOWN,
+ REGULAR,
+ DIRECTORY,
+ SYMLINK
+};
-/** Returns information about a file. This version throws an exception if an
-error occurs. */
-struct stat stat(const Path &fn);
+#ifdef MSVC
+typedef __uint64 FileSize;
+#else
+typedef unsigned long long FileSize;
+#endif
+
+/**
+Holds file information.
+*/
+class Stat
+{
+private:
+ struct Private;
+
+ FileType type;
+ FileSize size;
+ FileSize alloc_size;
+ Time::TimeStamp mtime;
+ std::string owner;
+ std::string group;
+
+ Stat();
+public:
+ FileType get_type() const { return type; }
+ bool is_regular() const { return type==REGULAR; }
+ bool is_directory() const { return type==DIRECTORY; }
+ bool is_symlink() const { return type==SYMLINK; }
+ FileSize get_size() const { return size; }
+ FileSize get_alloc_size() const { return alloc_size; }
+ const Time::TimeStamp &get_modify_time() const { return mtime; }
+ const std::string &get_owner() const { return owner; }
+ const std::string &get_group() const { return group; }
+
+ /// Returns a Stat object describing a file.
+ static Stat stat(const Path &);
+ static Stat lstat(const Path &);
+};
-/// Gets information about a file, without following symbolic links
-int lstat(const Path &fn, struct stat &st);
+/// Convenience wrapper for Stat::stat
+inline Stat stat(const Path &path)
+{ return Stat::stat(path); }
-/// Returns information about a file, without following symbolic links
-struct stat lstat(const Path &fn);
+/// Convenience wrapper for Stat::lstat
+inline Stat lstat(const Path &path)
+{ return Stat::lstat(path); }
/// Tests for existence of a file
bool exists(const Path &path);
/// Tests whether a path refers to an existing regular file
-bool is_reg(const Path &path);
+inline bool is_reg(const Path &path)
+{ return stat(path).is_regular(); }
/// Tests whether a path refers to an existing directory
-bool is_dir(const Path &path);
+inline bool is_dir(const Path &path)
+{ return stat(path).is_directory(); }
/// Tests whether a path refers to a symbolic link
-bool is_link(const Path &path);
+inline bool is_link(const Path &path)
+{ return lstat(path).is_symlink(); }
} // namespace FS
} // namespace Msp