aboutsummaryrefslogtreecommitdiff
path: root/libbutl/filesystem.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-05-19 11:41:16 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-05-19 11:41:16 +0200
commit70062c72cc7f0acef94a333247cc07df74cd3626 (patch)
tree1b66af2ee26e0bf2e3232fe389a0a22520dbd936 /libbutl/filesystem.hxx
parentcf9d0332f6b4dcd7dc388133ffd8fd6edd07e1c1 (diff)
Add file_empty(), extend path_entry() to return size
Diffstat (limited to 'libbutl/filesystem.hxx')
-rw-r--r--libbutl/filesystem.hxx24
1 files changed, 19 insertions, 5 deletions
diff --git a/libbutl/filesystem.hxx b/libbutl/filesystem.hxx
index 4fa1021..a6d7a4a 100644
--- a/libbutl/filesystem.hxx
+++ b/libbutl/filesystem.hxx
@@ -21,7 +21,7 @@
#endif
#include <cstddef> // ptrdiff_t
-#include <cstdint> // uint16_t
+#include <cstdint> // uint16_t, etc
#include <utility> // move(), pair
#include <iterator>
#include <functional>
@@ -73,23 +73,37 @@ namespace butl
other
};
+ // Filesystem entry info. The size is only meaningful for regular files.
+ //
+ struct entry_stat
+ {
+ entry_type type;
+ std::uint64_t size;
+ };
+
// Return a flag indicating if the path is to an existing file system entry
// and its type if so. Note that by default this function doesn't follow
// symlinks.
//
- LIBBUTL_EXPORT std::pair<bool, entry_type>
+ LIBBUTL_EXPORT std::pair<bool, entry_stat>
path_entry (const char*, bool follow_symlinks = false);
- inline std::pair<bool, entry_type>
+ inline std::pair<bool, entry_stat>
path_entry (const path& p, bool fs = false) {
return path_entry (p.string ().c_str (), fs);}
// Return true if the directory is empty. Note that the path must exist
- // and be a directory.
+ // and be a directory. This function follows symlinks.
//
- LIBBUTL_EXPORT bool
+ bool
dir_empty (const dir_path&);
+ // Return true if the file is empty. Note that the path must exist and be a
+ // regular file. This function follows symlinks.
+ //
+ bool
+ file_empty (const path&);
+
// Try to create a directory unless it already exists. If you expect
// the directory to exist and performance is important, then you
// should first call dir_exists() above since that's what this