libcosmos
Linux C++ System Programming Library
Loading...
Searching...
No Matches
FileBase.cxx
1// cosmos
2#include <cosmos/formatting.hxx>
3#include <cosmos/fs/FileBase.hxx>
4#include <cosmos/fs/filesystem.hxx>
5#include <cosmos/private/cosmos.hxx>
6#include <cosmos/utils.hxx>
7
8namespace cosmos {
9
10FileBase::~FileBase() {
11 const auto orig_fd = m_fd.raw();
12 try {
13 this->close();
14 } catch (const std::exception &e) {
15 noncritical_error(sprintf("%s: failed to close fd(%d)", __FUNCTION__, to_integral(orig_fd)), e);
16 }
17}
18
19void FileBase::truncate(const off_t bytes) {
20 fs::truncate(fd(), bytes);
21}
22
23} // end ns
virtual void close()
Close the current file object.
Definition FileBase.hxx:63
void truncate(const off_t length)
Definition FileBase.cxx:19
FileDescriptor fd() const
Allows access to the underlying fd with const semantics.
Definition FileBase.hxx:74
FileNum raw() const
Returns the primitive file descriptor contained in the object.