OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/shared_memory.h" | 5 #include "base/shared_memory.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <sys/mman.h> | 9 #include <sys/mman.h> |
10 #include <sys/stat.h> | 10 #include <sys/stat.h> |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 file_closer.reset(fp); // close when we go out of scope | 196 file_closer.reset(fp); // close when we go out of scope |
197 | 197 |
198 // Make sure the (new) file is the right size. | 198 // Make sure the (new) file is the right size. |
199 if (size && (posix_flags & (O_RDWR | O_CREAT))) { | 199 if (size && (posix_flags & (O_RDWR | O_CREAT))) { |
200 // Get current size. | 200 // Get current size. |
201 struct stat stat; | 201 struct stat stat; |
202 if (fstat(fileno(fp), &stat) != 0) | 202 if (fstat(fileno(fp), &stat) != 0) |
203 return false; | 203 return false; |
204 const size_t current_size = stat.st_size; | 204 const size_t current_size = stat.st_size; |
205 if (current_size != size) { | 205 if (current_size != size) { |
206 // TODO(hawk): When finished with bug 16371, revert this CHECK() to: | 206 if (ftruncate(fileno(fp), size) != 0) |
207 // if (ftruncate(fileno(fp), size) != 0) | 207 return false; |
208 // return false; | |
209 CHECK(!ftruncate(fileno(fp), size)); | |
210 if (fseeko(fp, size, SEEK_SET) != 0) | 208 if (fseeko(fp, size, SEEK_SET) != 0) |
211 return false; | 209 return false; |
212 } | 210 } |
213 } | 211 } |
214 | 212 |
215 mapped_file_ = dup(fileno(fp)); | 213 mapped_file_ = dup(fileno(fp)); |
216 if (mapped_file_ == -1) { | 214 if (mapped_file_ == -1) { |
217 if (errno == EMFILE) { | 215 if (errno == EMFILE) { |
218 LOG(WARNING) << "Shared memory creation failed; out of file descriptors"; | 216 LOG(WARNING) << "Shared memory creation failed; out of file descriptors"; |
219 return false; | 217 return false; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 | 302 |
305 void SharedMemory::Unlock() { | 303 void SharedMemory::Unlock() { |
306 LockOrUnlockCommon(F_ULOCK); | 304 LockOrUnlockCommon(F_ULOCK); |
307 } | 305 } |
308 | 306 |
309 SharedMemoryHandle SharedMemory::handle() const { | 307 SharedMemoryHandle SharedMemory::handle() const { |
310 return FileDescriptor(mapped_file_, false); | 308 return FileDescriptor(mapped_file_, false); |
311 } | 309 } |
312 | 310 |
313 } // namespace base | 311 } // namespace base |
OLD | NEW |