Chromium Code Reviews| 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; |
| - } |
| } |
| } |