mirror of
https://github.com/kichikuou/system3-sdl2.git
synced 2026-09-27 17:38:01 +03:00
nact: Change tvar from char array to std::string
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
#include "fileio.h"
|
||||
#include <vector>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
@@ -89,3 +90,17 @@ std::string FILEIO::gets()
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string FILEIO::read_string(size_t size) {
|
||||
std::vector<char> buf(size + 1);
|
||||
if (fread(buf.data(), size, 1, fp) != 1) {
|
||||
return std::string();
|
||||
}
|
||||
return std::string(buf.data());
|
||||
}
|
||||
|
||||
bool FILEIO::write_string(const std::string& str, size_t size) {
|
||||
std::vector<char> buf(size);
|
||||
memcpy(buf.data(), str.c_str(), std::min(size, str.size()));
|
||||
return fwrite(buf.data(), size, 1, fp) == 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user