Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2727)

Unified Diff: base/shared_memory_posix.cc

Issue 174482: Use ftruncate() instead of fwrite() to extend files.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/shared_memory_posix.cc
===================================================================
--- base/shared_memory_posix.cc (revision 24242)
+++ base/shared_memory_posix.cc (working copy)
@@ -194,8 +194,6 @@
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;
Mark Mentovai 2009/08/26 01:22:51 While you're here, move the declaration down to wh
pink (ping after 24hrs) 2009/08/26 15:16:57 Done.
@@ -203,24 +201,11 @@
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)
+ 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;
- }
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698