Index: base/file_util.h |
diff --git a/base/file_util.h b/base/file_util.h |
index 4154856724e4ce8404c1007470456ee66ec07b32..c546b9aac4a12852b16cf1013cee9386200a8eec 100644 |
--- a/base/file_util.h |
+++ b/base/file_util.h |
@@ -24,6 +24,7 @@ |
#include <vector> |
#include "base/basictypes.h" |
+#include "base/scoped_ptr.h" |
#include "base/file_path.h" |
namespace file_util { |
@@ -318,6 +319,10 @@ FILE* OpenFile(const std::wstring& filename, const char* mode); |
// Closes file opened by OpenFile. Returns true on success. |
bool CloseFile(FILE* file); |
+// Truncates an open file to end at the location of the current file pointer. |
+// This is a cross-platform analog to Windows' SetEndOfFile() function. |
+bool TruncateFile(FILE* file); |
+ |
// Reads the given number of bytes from the file into the buffer. Returns |
// the number of read bytes, or -1 on error. |
int ReadFile(const std::wstring& filename, char* data, int size); |
@@ -336,6 +341,18 @@ bool SetCurrentDirectory(const FilePath& path); |
// Deprecated temporary compatibility function. |
bool SetCurrentDirectory(const std::wstring& current_directory); |
+// A class to handle auto-closing of FILE*'s. |
+class ScopedFILEClose { |
+ public: |
+ inline void operator()(FILE* x) const { |
+ if (x) { |
+ fclose(x); |
+ } |
+ } |
+}; |
+ |
+typedef scoped_ptr_malloc<FILE, ScopedFILEClose> ScopedFILE; |
+ |
// A class for enumerating the files in a provided path. The order of the |
// results is not guaranteed. |
// |