#include <aclapi.h>
#else
#define _FILE_OFFSET_BITS 64
+#include <cerrno>
#include <sys/stat.h>
#include <grp.h>
#include <pwd.h>
Stat Stat::Private::from_struct_stat(const struct stat &st)
{
Stat result;
+ result.exists = true;
if(S_ISREG(st.st_mode))
result.type = REGULAR;
else if(S_ISDIR(st.st_mode))
#endif
Stat::Stat():
+ exists(false),
type(UNKNOWN),
size(0),
alloc_size(0)
struct stat st;
int ret = ::stat(path.str().c_str(), &st);
if(ret==-1)
- throw system_error("stat");
+ {
+ if(errno==ENOENT)
+ return Stat();
+ else
+ throw system_error("stat");
+ }
return Private::from_struct_stat(st);
#endif
struct stat st;
int ret = ::lstat(path.str().c_str(), &st);
if(ret==-1)
- throw system_error("lstat");
+ {
+ if(errno==ENOENT)
+ return Stat();
+ else
+ throw system_error("lstat");
+ }
return Private::from_struct_stat(st);
#endif
private:
struct Private;
+ bool exists;
FileType type;
FileSize size;
FileSize alloc_size;
std::string owner;
std::string group;
- Stat();
public:
+ Stat();
+
FileType get_type() const { return type; }
bool is_regular() const { return type==REGULAR; }
bool is_directory() const { return type==DIRECTORY; }
const std::string &get_owner() const { return owner; }
const std::string &get_group() const { return group; }
+ operator bool() const { return exists; }
+
/// Returns a Stat object describing a file.
static Stat stat(const Path &);
static Stat lstat(const Path &);