OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 fp = file_util::OpenFile(path, "w+x"); | 135 fp = file_util::OpenFile(path, "w+x"); |
136 if (fp == NULL && open_existing) { | 136 if (fp == NULL && open_existing) { |
137 // "w+" will truncate if it already exists. | 137 // "w+" will truncate if it already exists. |
138 fp = file_util::OpenFile(path, "a+"); | 138 fp = file_util::OpenFile(path, "a+"); |
139 fix_size = false; | 139 fix_size = false; |
140 } | 140 } |
141 } | 141 } |
142 if (fp && fix_size) { | 142 if (fp && fix_size) { |
143 // Get current size. | 143 // Get current size. |
144 struct stat stat; | 144 struct stat stat; |
145 if (fstat(fileno(fp), &stat) != 0) | 145 if (fstat(fileno(fp), &stat) != 0) { |
146 file_util::CloseFile(fp); | |
rvargas (doing something else)
2011/06/23 03:43:53
nit: it seems ScopedFILE could be used by this met
| |
146 return false; | 147 return false; |
148 } | |
147 const uint32 current_size = stat.st_size; | 149 const uint32 current_size = stat.st_size; |
148 if (current_size != size) { | 150 if (current_size != size) { |
149 if (HANDLE_EINTR(ftruncate(fileno(fp), size)) != 0) | 151 if (HANDLE_EINTR(ftruncate(fileno(fp), size)) != 0) { |
152 file_util::CloseFile(fp); | |
150 return false; | 153 return false; |
151 if (fseeko(fp, size, SEEK_SET) != 0) | 154 } |
155 if (fseeko(fp, size, SEEK_SET) != 0) { | |
156 file_util::CloseFile(fp); | |
152 return false; | 157 return false; |
158 } | |
153 } | 159 } |
154 created_size_ = size; | 160 created_size_ = size; |
155 } | 161 } |
156 if (fp == NULL) { | 162 if (fp == NULL) { |
157 #if !defined(OS_MACOSX) | 163 #if !defined(OS_MACOSX) |
158 PLOG(ERROR) << "Creating shared memory in " << path.value() << " failed"; | 164 PLOG(ERROR) << "Creating shared memory in " << path.value() << " failed"; |
159 FilePath dir = path.DirName(); | 165 FilePath dir = path.DirName(); |
160 if (access(dir.value().c_str(), W_OK | X_OK) < 0) { | 166 if (access(dir.value().c_str(), W_OK | X_OK) < 0) { |
161 PLOG(ERROR) << "Unable to access(W_OK|X_OK) " << dir.value(); | 167 PLOG(ERROR) << "Unable to access(W_OK|X_OK) " << dir.value(); |
162 if (dir.value() == "/dev/shm") { | 168 if (dir.value() == "/dev/shm") { |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
331 new_handle->fd = new_fd; | 337 new_handle->fd = new_fd; |
332 new_handle->auto_close = true; | 338 new_handle->auto_close = true; |
333 | 339 |
334 if (close_self) | 340 if (close_self) |
335 Close(); | 341 Close(); |
336 | 342 |
337 return true; | 343 return true; |
338 } | 344 } |
339 | 345 |
340 } // namespace base | 346 } // namespace base |
OLD | NEW |