summaryrefslogtreecommitdiffstats
path: root/base/file_util.cc
diff options
context:
space:
mode:
authorjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-27 19:08:39 +0000
committerjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-27 19:08:39 +0000
commitc2c998ce396ec7fd77d8e1277afb3f029f859341 (patch)
tree493fc8e08610c67c72ce2df6d0f1ddefcf53974d /base/file_util.cc
parentbd05da2be472b05c290261fbf99a4a3673982a7f (diff)
downloadchromium_src-c2c998ce396ec7fd77d8e1277afb3f029f859341.zip
chromium_src-c2c998ce396ec7fd77d8e1277afb3f029f859341.tar.gz
chromium_src-c2c998ce396ec7fd77d8e1277afb3f029f859341.tar.bz2
Roll forward 8722,8721
Review URL: http://codereview.chromium.org/19028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8734 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_util.cc')
-rw-r--r--base/file_util.cc21
1 files changed, 21 insertions, 0 deletions
diff --git a/base/file_util.cc b/base/file_util.cc
index 078e3afa..8ecb1cc 100644
--- a/base/file_util.cc
+++ b/base/file_util.cc
@@ -4,6 +4,9 @@
#include "base/file_util.h"
+#if defined(OS_WIN)
+#include <io.h>
+#endif
#include <stdio.h>
#include <fstream>
@@ -276,6 +279,24 @@ bool CloseFile(FILE* file) {
return fclose(file) == 0;
}
+bool TruncateFile(FILE* file) {
+ if (file == NULL)
+ return false;
+ long current_offset = ftell(file);
+ if (current_offset == -1)
+ return false;
+#if defined(OS_WIN)
+ int fd = _fileno(file);
+ if (_chsize(fd, current_offset) != 0)
+ return false;
+#else
+ int fd = fileno(file);
+ if (ftruncate(fd, current_offset) != 0)
+ return false;
+#endif
+ return true;
+}
+
bool ContainsPath(const FilePath &parent, const FilePath& child) {
FilePath abs_parent = FilePath(parent);
FilePath abs_child = FilePath(child);