summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorpinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-26 16:27:41 +0000
committerpinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-26 16:27:41 +0000
commit5710f5995f77c8b8e6db1ac667262a133d9c2fb7 (patch)
tree0e7d81bb8ad670a1f271e67f5bcc901d9e64836f /base
parent84fd488c8ecc79a01e69305a7dd498164a821fb0 (diff)
downloadchromium_src-5710f5995f77c8b8e6db1ac667262a133d9c2fb7.zip
chromium_src-5710f5995f77c8b8e6db1ac667262a133d9c2fb7.tar.gz
chromium_src-5710f5995f77c8b8e6db1ac667262a133d9c2fb7.tar.bz2
Use ftruncate() instead of fwrite() to extend files.
BUG=20249 TEST=Browser still works Review URL: http://codereview.chromium.org/174482 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24451 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/shared_memory_posix.cc24
1 files changed, 4 insertions, 20 deletions
diff --git a/base/shared_memory_posix.cc b/base/shared_memory_posix.cc
index 55adcb4..20a1ccb 100644
--- a/base/shared_memory_posix.cc
+++ b/base/shared_memory_posix.cc
@@ -194,33 +194,17 @@ bool SharedMemory::CreateOrOpen(const std::wstring &name,
file_closer.reset(fp); // close when we go out of scope
// Make sure the (new) file is the right size.
- // According to the man page, "Use of truncate() to extend a file is
- // not portable."
if (size && (posix_flags & (O_RDWR | O_CREAT))) {
// Get current size.
- size_t current_size = 0;
struct stat stat;
if (fstat(fileno(fp), &stat) != 0)
return false;
- current_size = stat.st_size;
- // Possibly grow.
- if (current_size < size) {
- if (fseeko(fp, current_size, SEEK_SET) != 0)
+ const size_t current_size = stat.st_size;
+ if (current_size != size) {
+ if (ftruncate(fileno(fp), size) != 0)
return false;
- size_t writesize = size - current_size;
- scoped_array<char> buf(new char[writesize]);
- memset(buf.get(), 0, writesize);
- if (fwrite(buf.get(), 1, writesize, fp) != writesize) {
- return false;
- }
- if (fflush(fp) != 0)
+ if (fseeko(fp, size, SEEK_SET) != 0)
return false;
- } else if (current_size > size) {
- // possibly shrink.
- if ((ftruncate(fileno(fp), size) != 0) ||
- (fflush(fp) != 0)) {
- return false;
- }
}
}