]> git.tdb.fi Git - libs/core.git/commitdiff
Include filename in errors from stat
authorMikko Rasa <tdb@tdb.fi>
Tue, 7 Apr 2015 11:05:12 +0000 (14:05 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 7 Apr 2015 11:05:12 +0000 (14:05 +0300)
source/fs/unix/stat.cpp
source/fs/windows/stat.cpp

index 1ba62cd1c3f8a752032c6f1a1baca95ce9a28051..352363316f5bf47a1739451a44c92c78da257c2e 100644 (file)
@@ -3,6 +3,7 @@
 #include <unistd.h>
 #include <sys/stat.h>
 #include <msp/core/systemerror.h>
+#include <msp/strings/format.h>
 #include "stat.h"
 #include "stat_private.h"
 
@@ -47,10 +48,11 @@ Stat Stat::stat(const Path &path)
        int ret = ::stat(path.str().c_str(), &st);
        if(ret==-1)
        {
-               if(errno==ENOENT)
+               int err = errno;
+               if(err==ENOENT)
                        return Stat();
                else
-                       throw system_error("stat");
+                       throw system_error(format("stat(%s)", path), err);
        }
 
        return Private::from_struct_stat(st);
@@ -62,10 +64,11 @@ Stat Stat::lstat(const Path &path)
        int ret = ::lstat(path.str().c_str(), &st);
        if(ret==-1)
        {
-               if(errno==ENOENT)
+               int err = errno;
+               if(err==ENOENT)
                        return Stat();
                else
-                       throw system_error("lstat");
+                       throw system_error(format("lstat(%s)", path), err);
        }
 
        return Private::from_struct_stat(st);
index 229d9e9485cda8a6c8e1f31d30b4f83fae232836..a1f19efa7de25f5bd462aa8f08dcde57726161c4 100644 (file)
@@ -80,7 +80,7 @@ Stat Stat::stat(const Path &path)
                if(err==ERROR_FILE_NOT_FOUND)
                        return Stat();
                else
-                       throw system_error("CreateFile", err);
+                       throw system_error(format("CreateFile(%s)", path), err);
        }
 
        BY_HANDLE_FILE_INFORMATION info;