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

Side by Side Diff: base/file_util_posix.cc

Issue 197873014: Revert of Implement ScopedFD in terms of ScopedGeneric. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/file_util.h ('k') | base/file_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/file_util.h" 5 #include "base/file_util.h"
6 6
7 #include <dirent.h> 7 #include <dirent.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <fcntl.h> 9 #include <fcntl.h>
10 #include <libgen.h> 10 #include <libgen.h>
(...skipping 15 matching lines...) Expand all
26 #include "base/mac/foundation_util.h" 26 #include "base/mac/foundation_util.h"
27 #elif !defined(OS_CHROMEOS) && defined(USE_GLIB) 27 #elif !defined(OS_CHROMEOS) && defined(USE_GLIB)
28 #include <glib.h> // for g_get_home_dir() 28 #include <glib.h> // for g_get_home_dir()
29 #endif 29 #endif
30 30
31 #include <fstream> 31 #include <fstream>
32 32
33 #include "base/basictypes.h" 33 #include "base/basictypes.h"
34 #include "base/files/file_enumerator.h" 34 #include "base/files/file_enumerator.h"
35 #include "base/files/file_path.h" 35 #include "base/files/file_path.h"
36 #include "base/files/scoped_file.h"
37 #include "base/logging.h" 36 #include "base/logging.h"
38 #include "base/memory/scoped_ptr.h" 37 #include "base/memory/scoped_ptr.h"
39 #include "base/memory/singleton.h" 38 #include "base/memory/singleton.h"
40 #include "base/path_service.h" 39 #include "base/path_service.h"
41 #include "base/posix/eintr_wrapper.h" 40 #include "base/posix/eintr_wrapper.h"
42 #include "base/stl_util.h" 41 #include "base/stl_util.h"
43 #include "base/strings/string_util.h" 42 #include "base/strings/string_util.h"
44 #include "base/strings/stringprintf.h" 43 #include "base/strings/stringprintf.h"
45 #include "base/strings/sys_string_conversions.h" 44 #include "base/strings/sys_string_conversions.h"
46 #include "base/strings/utf_string_conversions.h" 45 #include "base/strings/utf_string_conversions.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 165
167 #if defined(OS_LINUX) 166 #if defined(OS_LINUX)
168 // Determine if /dev/shm files can be mapped and then mprotect'd PROT_EXEC. 167 // Determine if /dev/shm files can be mapped and then mprotect'd PROT_EXEC.
169 // This depends on the mount options used for /dev/shm, which vary among 168 // This depends on the mount options used for /dev/shm, which vary among
170 // different Linux distributions and possibly local configuration. It also 169 // different Linux distributions and possibly local configuration. It also
171 // depends on details of kernel--ChromeOS uses the noexec option for /dev/shm 170 // depends on details of kernel--ChromeOS uses the noexec option for /dev/shm
172 // but its kernel allows mprotect with PROT_EXEC anyway. 171 // but its kernel allows mprotect with PROT_EXEC anyway.
173 bool DetermineDevShmExecutable() { 172 bool DetermineDevShmExecutable() {
174 bool result = false; 173 bool result = false;
175 FilePath path; 174 FilePath path;
176 175 int fd = CreateAndOpenFdForTemporaryFile(FilePath("/dev/shm"), &path);
177 ScopedFD fd(CreateAndOpenFdForTemporaryFile(FilePath("/dev/shm"), &path)); 176 if (fd >= 0) {
178 if (fd.is_valid()) { 177 file_util::ScopedFD shm_fd_closer(&fd);
179 DeleteFile(path, false); 178 DeleteFile(path, false);
180 long sysconf_result = sysconf(_SC_PAGESIZE); 179 long sysconf_result = sysconf(_SC_PAGESIZE);
181 CHECK_GE(sysconf_result, 0); 180 CHECK_GE(sysconf_result, 0);
182 size_t pagesize = static_cast<size_t>(sysconf_result); 181 size_t pagesize = static_cast<size_t>(sysconf_result);
183 CHECK_GE(sizeof(pagesize), sizeof(sysconf_result)); 182 CHECK_GE(sizeof(pagesize), sizeof(sysconf_result));
184 void *mapping = mmap(NULL, pagesize, PROT_READ, MAP_SHARED, fd.get(), 0); 183 void *mapping = mmap(NULL, pagesize, PROT_READ, MAP_SHARED, fd, 0);
185 if (mapping != MAP_FAILED) { 184 if (mapping != MAP_FAILED) {
186 if (mprotect(mapping, pagesize, PROT_READ | PROT_EXEC) == 0) 185 if (mprotect(mapping, pagesize, PROT_READ | PROT_EXEC) == 0)
187 result = true; 186 result = true;
188 munmap(mapping, pagesize); 187 munmap(mapping, pagesize);
189 } 188 }
190 } 189 }
191 return result; 190 return result;
192 } 191 }
193 #endif // defined(OS_LINUX) 192 #endif // defined(OS_LINUX)
194 193
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 if (S_ISLNK(st.st_mode)) 653 if (S_ISLNK(st.st_mode))
655 return true; 654 return true;
656 else 655 else
657 return false; 656 return false;
658 } 657 }
659 658
660 bool GetFileInfo(const FilePath& file_path, File::Info* results) { 659 bool GetFileInfo(const FilePath& file_path, File::Info* results) {
661 stat_wrapper_t file_info; 660 stat_wrapper_t file_info;
662 #if defined(OS_ANDROID) 661 #if defined(OS_ANDROID)
663 if (file_path.IsContentUri()) { 662 if (file_path.IsContentUri()) {
664 ScopedFD fd(OpenContentUriForRead(file_path)); 663 int fd = OpenContentUriForRead(file_path);
665 if (!fd.is_valid()) 664 if (fd < 0)
666 return false; 665 return false;
667 if (CallFstat(fd.get(), &file_info) != 0) 666 file_util::ScopedFD scoped_fd(&fd);
667 if (CallFstat(fd, &file_info) != 0)
668 return false; 668 return false;
669 } else { 669 } else {
670 #endif // defined(OS_ANDROID) 670 #endif // defined(OS_ANDROID)
671 if (CallStat(file_path.value().c_str(), &file_info) != 0) 671 if (CallStat(file_path.value().c_str(), &file_info) != 0)
672 return false; 672 return false;
673 #if defined(OS_ANDROID) 673 #if defined(OS_ANDROID)
674 } 674 }
675 #endif // defined(OS_ANDROID) 675 #endif // defined(OS_ANDROID)
676 results->is_directory = S_ISDIR(file_info.st_mode); 676 results->is_directory = S_ISDIR(file_info.st_mode);
677 results->size = file_info.st_size; 677 results->size = file_info.st_size;
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 result = false; 921 result = false;
922 if (IGNORE_EINTR(close(outfile)) < 0) 922 if (IGNORE_EINTR(close(outfile)) < 0)
923 result = false; 923 result = false;
924 924
925 return result; 925 return result;
926 } 926 }
927 #endif // !defined(OS_MACOSX) 927 #endif // !defined(OS_MACOSX)
928 928
929 } // namespace internal 929 } // namespace internal
930 } // namespace base 930 } // namespace base
OLDNEW
« no previous file with comments | « base/file_util.h ('k') | base/file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698