diff --git a/WFObj.cc b/WFObj.cc index 1c43d3b..01520af 100644 --- a/WFObj.cc +++ b/WFObj.cc @@ -415,7 +415,22 @@ void WFObj::loadMaterial(const std::string & name) bool WFObj::loadfile(const char *path, Buffer *buff) { - /* TODO */ + struct stat st; + + if ( (stat(path, &st) == 0) && (st.st_size > 0) ) + { + int fd = open(path, O_RDONLY); + if (fd > 0) + { + buff->alloc(st.st_size); + int num_read = read(fd, buff->data, st.st_size); + close(fd); + if (num_read > 0) + return true; + } + } + + return false; } bool WFObj::VertexRef::operator<(const VertexRef & other) diff --git a/WFObj.h b/WFObj.h index 927773a..bb8c4a5 100644 --- a/WFObj.h +++ b/WFObj.h @@ -14,8 +14,18 @@ public: class Buffer { public: + Buffer() : m_alloc(false) {} + ~Buffer() { if (m_alloc) delete data; } uint8_t *data; size_t length; + void alloc(size_t sz) + { + length = sz; + data = new uint8_t[sz]; + m_alloc = true; + } + protected: + bool m_alloc; }; typedef bool (*loadfile_t)(const char *fname, Buffer *buff);