OLD | NEW |
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 #endif | 54 #endif |
55 | 55 |
56 #if !defined(OS_IOS) | 56 #if !defined(OS_IOS) |
57 #include <grp.h> | 57 #include <grp.h> |
58 #endif | 58 #endif |
59 | 59 |
60 namespace base { | 60 namespace base { |
61 | 61 |
62 namespace { | 62 namespace { |
63 | 63 |
64 #if defined(OS_BSD) || defined(OS_MACOSX) | 64 #if defined(OS_BSD) || defined(OS_MACOSX) || defined(OS_NACL) |
65 typedef struct stat stat_wrapper_t; | |
66 static int CallStat(const char *path, stat_wrapper_t *sb) { | 65 static int CallStat(const char *path, stat_wrapper_t *sb) { |
67 ThreadRestrictions::AssertIOAllowed(); | 66 ThreadRestrictions::AssertIOAllowed(); |
68 return stat(path, sb); | 67 return stat(path, sb); |
69 } | 68 } |
70 static int CallLstat(const char *path, stat_wrapper_t *sb) { | 69 static int CallLstat(const char *path, stat_wrapper_t *sb) { |
71 ThreadRestrictions::AssertIOAllowed(); | 70 ThreadRestrictions::AssertIOAllowed(); |
72 return lstat(path, sb); | 71 return lstat(path, sb); |
73 } | 72 } |
74 #else // defined(OS_BSD) || defined(OS_MACOSX) | 73 #else // defined(OS_BSD) || defined(OS_MACOSX) || defined(OS_NACL) |
75 typedef struct stat64 stat_wrapper_t; | |
76 static int CallStat(const char *path, stat_wrapper_t *sb) { | 74 static int CallStat(const char *path, stat_wrapper_t *sb) { |
77 ThreadRestrictions::AssertIOAllowed(); | 75 ThreadRestrictions::AssertIOAllowed(); |
78 return stat64(path, sb); | 76 return stat64(path, sb); |
79 } | 77 } |
80 static int CallLstat(const char *path, stat_wrapper_t *sb) { | 78 static int CallLstat(const char *path, stat_wrapper_t *sb) { |
81 ThreadRestrictions::AssertIOAllowed(); | 79 ThreadRestrictions::AssertIOAllowed(); |
82 return lstat64(path, sb); | 80 return lstat64(path, sb); |
83 } | 81 } |
84 #endif // !(defined(OS_BSD) || defined(OS_MACOSX)) | 82 #endif // !(defined(OS_BSD) || defined(OS_MACOSX) || defined(OS_NACL)) |
85 | 83 |
86 // Helper for NormalizeFilePath(), defined below. | 84 // Helper for NormalizeFilePath(), defined below. |
87 bool RealPath(const FilePath& path, FilePath* real_path) { | 85 bool RealPath(const FilePath& path, FilePath* real_path) { |
88 ThreadRestrictions::AssertIOAllowed(); // For realpath(). | 86 ThreadRestrictions::AssertIOAllowed(); // For realpath(). |
89 FilePath::CharType buf[PATH_MAX]; | 87 FilePath::CharType buf[PATH_MAX]; |
90 if (!realpath(path.value().c_str(), buf)) | 88 if (!realpath(path.value().c_str(), buf)) |
91 return false; | 89 return false; |
92 | 90 |
93 *real_path = FilePath(buf); | 91 *real_path = FilePath(buf); |
94 return true; | 92 return true; |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 if (!file.IsValid()) | 630 if (!file.IsValid()) |
633 return false; | 631 return false; |
634 return file.GetInfo(results); | 632 return file.GetInfo(results); |
635 } else { | 633 } else { |
636 #endif // defined(OS_ANDROID) | 634 #endif // defined(OS_ANDROID) |
637 if (CallStat(file_path.value().c_str(), &file_info) != 0) | 635 if (CallStat(file_path.value().c_str(), &file_info) != 0) |
638 return false; | 636 return false; |
639 #if defined(OS_ANDROID) | 637 #if defined(OS_ANDROID) |
640 } | 638 } |
641 #endif // defined(OS_ANDROID) | 639 #endif // defined(OS_ANDROID) |
642 results->is_directory = S_ISDIR(file_info.st_mode); | 640 |
643 results->size = file_info.st_size; | 641 results->FromStat(file_info); |
644 #if defined(OS_MACOSX) || (defined(OS_FREEBSD) && __FreeBSD_version < 900000) | |
645 results->last_modified = Time::FromTimeSpec(file_info.st_mtimespec); | |
646 results->last_accessed = Time::FromTimeSpec(file_info.st_atimespec); | |
647 results->creation_time = Time::FromTimeSpec(file_info.st_ctimespec); | |
648 #elif defined(OS_ANDROID) | |
649 results->last_modified = Time::FromTimeT(file_info.st_mtime); | |
650 results->last_accessed = Time::FromTimeT(file_info.st_atime); | |
651 results->creation_time = Time::FromTimeT(file_info.st_ctime); | |
652 #else | |
653 results->last_modified = Time::FromTimeSpec(file_info.st_mtim); | |
654 results->last_accessed = Time::FromTimeSpec(file_info.st_atim); | |
655 results->creation_time = Time::FromTimeSpec(file_info.st_ctim); | |
656 #endif | |
657 return true; | 642 return true; |
658 } | 643 } |
659 | 644 |
660 FILE* OpenFile(const FilePath& filename, const char* mode) { | 645 FILE* OpenFile(const FilePath& filename, const char* mode) { |
661 ThreadRestrictions::AssertIOAllowed(); | 646 ThreadRestrictions::AssertIOAllowed(); |
662 FILE* result = NULL; | 647 FILE* result = NULL; |
663 do { | 648 do { |
664 result = fopen(filename.value().c_str(), mode); | 649 result = fopen(filename.value().c_str(), mode); |
665 } while (!result && errno == EINTR); | 650 } while (!result && errno == EINTR); |
666 return result; | 651 return result; |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
905 result = false; | 890 result = false; |
906 if (IGNORE_EINTR(close(outfile)) < 0) | 891 if (IGNORE_EINTR(close(outfile)) < 0) |
907 result = false; | 892 result = false; |
908 | 893 |
909 return result; | 894 return result; |
910 } | 895 } |
911 #endif // !defined(OS_MACOSX) | 896 #endif // !defined(OS_MACOSX) |
912 | 897 |
913 } // namespace internal | 898 } // namespace internal |
914 } // namespace base | 899 } // namespace base |
OLD | NEW |