#include "RawModelLoader.h"
+#include "cwrap/Fildes.h"
+
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
} // namespace
-namespace
-{
-
-class OwnedFileDescriptor final
-{
-public:
- OwnedFileDescriptor(int value) : _value{value}
- {
- // DO NOTHING
- }
-
-public:
- // NOTE Copy is not allowed
- OwnedFileDescriptor(const OwnedFileDescriptor &) = delete;
-
-public:
- // NOTE Move is allowed
- OwnedFileDescriptor(OwnedFileDescriptor &&fd) { _value = fd.release(); }
-
-public:
- ~OwnedFileDescriptor()
- {
- if (_value != -1)
- {
- // Close on descturction
- close(_value);
- }
- }
-
-public:
- int value(void) const { return _value; }
-
-public:
- int release(void)
- {
- auto res = _value;
- _value = -1;
- return res;
- }
-
-private:
- int _value = -1;
-};
-
-} // namespace
-
std::unique_ptr<RawModel> load_from(const std::string &path)
{
- OwnedFileDescriptor fd = open(path.c_str(), O_RDONLY);
+ cwrap::Fildes fildes{open(path.c_str(), O_RDONLY)};
- if (fd.value() == -1)
+ if (fildes.get() == -1)
{
// Return nullptr on open failure
return nullptr;
}
struct stat st;
- if (fstat(fd.value(), &st) == -1)
+ if (fstat(fildes.get(), &st) == -1)
{
// Return nullptr on fstat failure
return nullptr;