Spectre/System/File: adding readString()
This commit is contained in:
parent
99ae7f2236
commit
c11d71aaaa
2 changed files with 18 additions and 0 deletions
|
|
@ -88,6 +88,9 @@ public :
|
|||
return read((void*) &buffer[0], s) == s;
|
||||
}
|
||||
|
||||
// Read contents into str until null (\0)
|
||||
size_t readString(std::string &str);
|
||||
|
||||
// Write data to file at the current position.
|
||||
// Returns -1 if an error occured. Otherwice the number of bytes written is returned.
|
||||
size_t write(const void *ptr, size_t size);
|
||||
|
|
|
|||
|
|
@ -140,6 +140,21 @@ size_t File::read(void *ptr, size_t size)
|
|||
return -1;
|
||||
}
|
||||
|
||||
size_t File::readString(std::string &str)
|
||||
{
|
||||
if (isOpen()) {
|
||||
for(;;) {
|
||||
int c = ::getc(m_handle);
|
||||
if (c == EOF || c == '\0') {
|
||||
break;
|
||||
}
|
||||
str.push_back(c);
|
||||
}
|
||||
return str.length();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
size_t File::write(const void *ptr, size_t size)
|
||||
{
|
||||
if (isOpen()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue