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

Side by Side Diff: base/file_util_posix.cc

Issue 7184032: Upstream android file related code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove android specific shmem method Created 9 years, 6 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
OLDNEW
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/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 <fnmatch.h> 10 #include <fnmatch.h>
11 #include <libgen.h> 11 #include <libgen.h>
12 #include <limits.h> 12 #include <limits.h>
13 #include <stdio.h> 13 #include <stdio.h>
14 #include <stdlib.h> 14 #include <stdlib.h>
15 #include <string.h> 15 #include <string.h>
16 #include <sys/errno.h> 16 #include <sys/errno.h>
17 #include <sys/mman.h> 17 #include <sys/mman.h>
18 #include <sys/param.h> 18 #include <sys/param.h>
19 #include <sys/stat.h> 19 #include <sys/stat.h>
20 #include <sys/time.h> 20 #include <sys/time.h>
21 #include <sys/types.h> 21 #include <sys/types.h>
22 #include <time.h> 22 #include <time.h>
23 #include <unistd.h> 23 #include <unistd.h>
24 24
25 #if defined(OS_MACOSX) 25 #if defined(OS_MACOSX)
26 #include <AvailabilityMacros.h> 26 #include <AvailabilityMacros.h>
27 #include "base/mac/foundation_util.h" 27 #include "base/mac/foundation_util.h"
28 #else 28 #elif !defined(OS_ANDROID)
29 #include <glib.h> 29 #include <glib.h>
30 #endif 30 #endif
31 31
32 #include <fstream> 32 #include <fstream>
33 33
34 #include "base/basictypes.h" 34 #include "base/basictypes.h"
35 #include "base/eintr_wrapper.h" 35 #include "base/eintr_wrapper.h"
36 #include "base/file_path.h" 36 #include "base/file_path.h"
37 #include "base/logging.h" 37 #include "base/logging.h"
38 #include "base/memory/scoped_ptr.h" 38 #include "base/memory/scoped_ptr.h"
39 #include "base/memory/singleton.h" 39 #include "base/memory/singleton.h"
40 #include "base/string_util.h" 40 #include "base/string_util.h"
41 #include "base/stringprintf.h" 41 #include "base/stringprintf.h"
42 #include "base/sys_string_conversions.h" 42 #include "base/sys_string_conversions.h"
43 #include "base/threading/thread_restrictions.h" 43 #include "base/threading/thread_restrictions.h"
44 #include "base/time.h" 44 #include "base/time.h"
45 #include "base/utf_string_conversions.h" 45 #include "base/utf_string_conversions.h"
46 46
47 #if defined(OS_ANDROID)
48 #include "base/os_compat_android.h"
49 #endif
50
47 namespace file_util { 51 namespace file_util {
48 52
49 namespace { 53 namespace {
50 54
51 // Helper for NormalizeFilePath(), defined below. 55 // Helper for NormalizeFilePath(), defined below.
52 bool RealPath(const FilePath& path, FilePath* real_path) { 56 bool RealPath(const FilePath& path, FilePath* real_path) {
53 base::ThreadRestrictions::AssertIOAllowed(); // For realpath(). 57 base::ThreadRestrictions::AssertIOAllowed(); // For realpath().
54 FilePath::CharType buf[PATH_MAX]; 58 FilePath::CharType buf[PATH_MAX];
55 if (!realpath(path.value().c_str(), buf)) 59 if (!realpath(path.value().c_str(), buf))
56 return false; 60 return false;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 } 103 }
100 104
101 int CountFilesCreatedAfter(const FilePath& path, 105 int CountFilesCreatedAfter(const FilePath& path,
102 const base::Time& comparison_time) { 106 const base::Time& comparison_time) {
103 base::ThreadRestrictions::AssertIOAllowed(); 107 base::ThreadRestrictions::AssertIOAllowed();
104 int file_count = 0; 108 int file_count = 0;
105 109
106 DIR* dir = opendir(path.value().c_str()); 110 DIR* dir = opendir(path.value().c_str());
107 if (dir) { 111 if (dir) {
108 #if !defined(OS_LINUX) && !defined(OS_MACOSX) && !defined(OS_FREEBSD) && \ 112 #if !defined(OS_LINUX) && !defined(OS_MACOSX) && !defined(OS_FREEBSD) && \
109 !defined(OS_OPENBSD) && !defined(OS_SOLARIS) 113 !defined(OS_OPENBSD) && !defined(OS_SOLARIS) && !defined(OS_ANDROID)
110 #error Port warning: depending on the definition of struct dirent, \ 114 #error Port warning: depending on the definition of struct dirent, \
111 additional space for pathname may be needed 115 additional space for pathname may be needed
112 #endif 116 #endif
113 struct dirent ent_buf; 117 struct dirent ent_buf;
114 struct dirent* ent; 118 struct dirent* ent;
115 while (readdir_r(dir, &ent_buf, &ent) == 0 && ent) { 119 while (readdir_r(dir, &ent_buf, &ent) == 0 && ent) {
116 if ((strcmp(ent->d_name, ".") == 0) || 120 if ((strcmp(ent->d_name, ".") == 0) ||
117 (strcmp(ent->d_name, "..") == 0)) 121 (strcmp(ent->d_name, "..") == 0))
118 continue; 122 continue;
119 123
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 } 736 }
733 737
734 bool FileEnumerator::ReadDirectory(std::vector<DirectoryEntryInfo>* entries, 738 bool FileEnumerator::ReadDirectory(std::vector<DirectoryEntryInfo>* entries,
735 const FilePath& source, bool show_links) { 739 const FilePath& source, bool show_links) {
736 base::ThreadRestrictions::AssertIOAllowed(); 740 base::ThreadRestrictions::AssertIOAllowed();
737 DIR* dir = opendir(source.value().c_str()); 741 DIR* dir = opendir(source.value().c_str());
738 if (!dir) 742 if (!dir)
739 return false; 743 return false;
740 744
741 #if !defined(OS_LINUX) && !defined(OS_MACOSX) && !defined(OS_FREEBSD) && \ 745 #if !defined(OS_LINUX) && !defined(OS_MACOSX) && !defined(OS_FREEBSD) && \
742 !defined(OS_OPENBSD) && !defined(OS_SOLARIS) 746 !defined(OS_OPENBSD) && !defined(OS_SOLARIS) && !defined(OS_ANDROID)
743 #error Port warning: depending on the definition of struct dirent, \ 747 #error Port warning: depending on the definition of struct dirent, \
744 additional space for pathname may be needed 748 additional space for pathname may be needed
745 #endif 749 #endif
746 750
747 struct dirent dent_buf; 751 struct dirent dent_buf;
748 struct dirent* dent; 752 struct dirent* dent;
749 while (readdir_r(dir, &dent_buf, &dent) == 0 && dent) { 753 while (readdir_r(dir, &dent_buf, &dent) == 0 && dent) {
750 DirectoryEntryInfo info; 754 DirectoryEntryInfo info;
751 info.filename = FilePath(dent->d_name); 755 info.filename = FilePath(dent->d_name);
752 756
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 *normalized_path = real_path_result; 836 *normalized_path = real_path_result;
833 return true; 837 return true;
834 } 838 }
835 839
836 #if !defined(OS_MACOSX) 840 #if !defined(OS_MACOSX)
837 bool GetTempDir(FilePath* path) { 841 bool GetTempDir(FilePath* path) {
838 const char* tmp = getenv("TMPDIR"); 842 const char* tmp = getenv("TMPDIR");
839 if (tmp) 843 if (tmp)
840 *path = FilePath(tmp); 844 *path = FilePath(tmp);
841 else 845 else
846 #if defined(OS_ANDROID)
847 *path = FilePath("/data/local/tmp");
848 #else
842 *path = FilePath("/tmp"); 849 *path = FilePath("/tmp");
850 #endif
843 return true; 851 return true;
844 } 852 }
845 853
854 #if !defined(OS_ANDROID)
846 bool GetShmemTempDir(FilePath* path) { 855 bool GetShmemTempDir(FilePath* path) {
847 *path = FilePath("/dev/shm"); 856 *path = FilePath("/dev/shm");
848 return true; 857 return true;
849 } 858 }
859 #endif
850 860
851 FilePath GetHomeDir() { 861 FilePath GetHomeDir() {
852 const char* home_dir = getenv("HOME"); 862 const char* home_dir = getenv("HOME");
853 if (home_dir && home_dir[0]) 863 if (home_dir && home_dir[0])
854 return FilePath(home_dir); 864 return FilePath(home_dir);
855 865
866 #if defined(OS_ANDROID)
867 LOG(WARNING) << "OS_ANDROID: Home directory lookup not yet implemented.";
868 #else
856 // g_get_home_dir calls getpwent, which can fall through to LDAP calls. 869 // g_get_home_dir calls getpwent, which can fall through to LDAP calls.
857 base::ThreadRestrictions::AssertIOAllowed(); 870 base::ThreadRestrictions::AssertIOAllowed();
858 871
859 home_dir = g_get_home_dir(); 872 home_dir = g_get_home_dir();
860 if (home_dir && home_dir[0]) 873 if (home_dir && home_dir[0])
861 return FilePath(home_dir); 874 return FilePath(home_dir);
875 #endif
862 876
863 FilePath rv; 877 FilePath rv;
864 if (file_util::GetTempDir(&rv)) 878 if (file_util::GetTempDir(&rv))
865 return rv; 879 return rv;
866 880
867 // Last resort. 881 // Last resort.
868 return FilePath("/tmp"); 882 return FilePath("/tmp");
869 } 883 }
870 884
871 bool CopyFile(const FilePath& from_path, const FilePath& to_path) { 885 bool CopyFile(const FilePath& from_path, const FilePath& to_path) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 if (HANDLE_EINTR(close(infile)) < 0) 924 if (HANDLE_EINTR(close(infile)) < 0)
911 result = false; 925 result = false;
912 if (HANDLE_EINTR(close(outfile)) < 0) 926 if (HANDLE_EINTR(close(outfile)) < 0)
913 result = false; 927 result = false;
914 928
915 return result; 929 return result;
916 } 930 }
917 #endif // defined(OS_MACOSX) 931 #endif // defined(OS_MACOSX)
918 932
919 } // namespace file_util 933 } // namespace file_util
OLDNEW
« no previous file with comments | « base/file_util_android.cc ('k') | base/os_compat_android.h » ('j') | base/shared_memory_posix.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698