40 FILE*
File::Open(
const std::string& filename,
const std::string& mode) {
41 return fopen(filename.c_str(), mode.c_str());
45 const std::string& mode) {
46 FILE* stream = fopen(filename.c_str(), mode.c_str());
47 if (stream ==
nullptr) {
48 tprintf(
"Unable to open '%s' in mode '%s'\n", filename.c_str(),
55 const std::string& filename) {
56 FILE* stream = fopen(filename.c_str(),
"wb");
57 if (stream ==
nullptr) {
58 tprintf(
"Unable to open '%s' for writing\n", filename.c_str());
61 fputs(str.c_str(), stream);
66 FILE* stream = fopen(filename.c_str(),
"rb");
67 if (stream ==
nullptr) {
75 FILE* stream =
File::Open(filename.c_str(),
"rb");
76 if (stream ==
nullptr)
return false;
83 std::string
File::JoinPath(
const std::string& prefix,
const std::string& suffix) {
84 return (prefix.empty() || prefix[prefix.size() - 1] ==
'/')
86 : prefix +
"/" + suffix;
90 #if !defined(_WIN32) || defined(__MINGW32__) 91 const int status = unlink(pathname);
93 const int status = _unlink(pathname);
96 tprintf(
"ERROR: Unable to delete file %s\n", pathname);
104 WIN32_FIND_DATA data;
106 HANDLE handle = FindFirstFile(pattern, &data);
107 bool all_deleted =
true;
108 if (handle != INVALID_HANDLE_VALUE) {
109 for (; result; result = FindNextFile(handle, &data)) {
120 bool all_deleted =
true;
121 if (glob(pattern, 0,
nullptr, &pglob) == 0) {
122 for (paths = pglob.gl_pathv; *paths !=
nullptr; paths++) {
136 fseek(stream_, 0, SEEK_END);
137 filesize_ = ftell(stream_);
138 fseek(stream_, 0, SEEK_SET);
143 fseek(stream_, 0, SEEK_END);
144 filesize_ = ftell(stream_);
145 fseek(stream_, 0, SEEK_SET);
149 if (stream_ !=
nullptr) {
155 char buf[BUFSIZ + 1];
157 while ((l = fread(buf, 1, BUFSIZ, stream_)) > 0) {
158 if (ferror(stream_)) {
169 int ret = fclose(stream_);
187 if (stream_ !=
nullptr) {
193 fputs(str.c_str(), stream_);
197 int ret = fclose(stream_);
OutputBuffer(FILE *stream)
static bool Readable(const std::string &filename)
static void WriteStringToFileOrDie(const std::string &str, const std::string &filename)
void WriteString(const std::string &str)
bool Read(std::string *out)
InputBuffer(FILE *stream)
static FILE * Open(const std::string &filename, const std::string &mode)
static FILE * OpenOrDie(const std::string &filename, const std::string &mode)
static bool ReadFileToString(const std::string &filename, std::string *out)
DLLSYM void tprintf(const char *format,...)
static bool Delete(const char *pathname)
static bool DeleteMatchingFiles(const char *pattern)
static std::string JoinPath(const std::string &prefix, const std::string &suffix)