diff options
author | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-27 17:13:02 +0000 |
---|---|---|
committer | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-27 17:13:02 +0000 |
commit | 6e01dae641ad11e7600dec30de45b506b8d21c0c (patch) | |
tree | bc27f693251a8e602fbdf65c50fd4379cd48959c /base/file_util.cc | |
parent | 25fa78c2ffe3e98231cfb22f4005452da85b201c (diff) | |
download | chromium_src-6e01dae641ad11e7600dec30de45b506b8d21c0c.zip chromium_src-6e01dae641ad11e7600dec30de45b506b8d21c0c.tar.gz chromium_src-6e01dae641ad11e7600dec30de45b506b8d21c0c.tar.bz2 |
First step of porting VisitedLinkMaster to POSIX:
* Use POSIX file access APIs rather than HANDLEs.
* Add stubs so that VisitedLinkMaster compiles on POSIX.
Still to be done:
* Bring up Surrounding infrastructure to turn on unit tests.
Review URL: http://codereview.chromium.org/18530
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8721 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_util.cc')
-rw-r--r-- | base/file_util.cc | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/base/file_util.cc b/base/file_util.cc index 078e3afa..f21ff07 100644 --- a/base/file_util.cc +++ b/base/file_util.cc @@ -276,6 +276,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); |