TTF Loading Fixed
This commit is contained in:
@@ -166,18 +166,26 @@ size_t File::readAhead(char *buffer, size_t max, char needle) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool_t File::writeString(std::string in) {
|
||||
size_t File::readToBuffer(char **buffer) {
|
||||
if(!this->isOpen()) {
|
||||
if(!this->open(FILE_MODE_WRITE)) return false;
|
||||
if(!this->open(FILE_MODE_READ)) return 0;
|
||||
}
|
||||
assertTrue(this->mode == FILE_MODE_READ);
|
||||
|
||||
if((*buffer) == nullptr) *buffer = (char*)malloc(this->length);
|
||||
fseek(this->file, 0, SEEK_SET);
|
||||
auto l = fread((*buffer), sizeof(char), this->length, this->file);
|
||||
return l;
|
||||
}
|
||||
|
||||
bool_t File::writeString(std::string in) {
|
||||
if(!this->isOpen() && !this->open(FILE_MODE_WRITE)) return false;
|
||||
assertTrue(this->mode == FILE_MODE_WRITE);
|
||||
return this->writeRaw((char *)in.c_str(), in.size()) && this->length == in.size();
|
||||
}
|
||||
|
||||
bool_t File::writeRaw(char *data, size_t len) {
|
||||
if(!this->isOpen()) {
|
||||
if(!this->open(FILE_MODE_WRITE)) return false;
|
||||
}
|
||||
if(!this->isOpen() && !this->open(FILE_MODE_WRITE)) return false;
|
||||
assertTrue(this->mode == FILE_MODE_WRITE);
|
||||
this->length = fwrite(data, sizeof(char_t), len, this->file);
|
||||
return true;
|
||||
|
@@ -109,6 +109,15 @@ namespace Dawn {
|
||||
char needle
|
||||
);
|
||||
|
||||
/**
|
||||
* Reads the contents of this file into a given buffer. If buffer is null
|
||||
* then the buffer will be allocated and returned.
|
||||
*
|
||||
* @param buffer Pointer to buffer to read to.
|
||||
* @return The size of the read data.
|
||||
*/
|
||||
size_t readToBuffer(char **buffer);
|
||||
|
||||
/**
|
||||
* Writes the entire contents of a string to a file.
|
||||
*
|
||||
|
Reference in New Issue
Block a user