fill WFObj::loadfile(), add Buffer allocation

This commit is contained in:
Josh Holtrop 2011-04-20 15:20:10 -04:00
parent ffe2fe1d92
commit a46b5baa05
2 changed files with 26 additions and 1 deletions

View File

@ -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)

10
WFObj.h
View File

@ -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);