aboutsummaryrefslogtreecommitdiff
path: root/common/file.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'common/file.cpp')
-rw-r--r--common/file.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/common/file.cpp b/common/file.cpp
index 5b465b5e01..fb837b9499 100644
--- a/common/file.cpp
+++ b/common/file.cpp
@@ -494,6 +494,28 @@ bool DumpFile::open(const String &filename) {
return _handle != NULL;
}
+bool DumpFile::open(const FilesystemNode &node) {
+ assert(!_handle);
+
+ if (node.isDirectory()) {
+ warning("File::open: Trying to open a FilesystemNode which is a directory");
+ return false;
+ } /*else if (!node.isReadable() && mode == kFileReadMode) {
+ warning("File::open: Trying to open an unreadable FilesystemNode object for reading");
+ return false;
+ } else if (!node.isWritable() && mode == kFileWriteMode) {
+ warning("File::open: Trying to open an unwritable FilesystemNode object for writing");
+ return false;
+ }*/
+
+ _handle = fopen(node.getPath().c_str(), "wb");
+
+ if (_handle == NULL)
+ debug(2, "File %s not found", node.getName().c_str());
+
+ return _handle != NULL;
+}
+
void DumpFile::close() {
if (_handle)
fclose((FILE *)_handle);
@@ -528,5 +550,12 @@ uint32 DumpFile::write(const void *ptr, uint32 len) {
return (uint32)fwrite(ptr, 1, len, (FILE *)_handle);
}
+void DumpFile::flush() {
+ assert(_handle);
+ // TODO: Should check the return value of fflush, and if it is non-zero,
+ // check errno and set an error flag.
+ fflush((FILE *)_handle);
+}
+
} // End of namespace Common