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/files/file_util.h" | 5 #include "base/files/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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 #include "base/android/content_uri_utils.h" | 52 #include "base/android/content_uri_utils.h" |
53 #include "base/os_compat_android.h" | 53 #include "base/os_compat_android.h" |
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 #if !defined(__native_client_nonsfi__) | 62 #if !defined(OS_NACL_NONSFI) |
63 namespace { | 63 namespace { |
64 | 64 |
65 #if defined(OS_BSD) || defined(OS_MACOSX) || defined(OS_NACL) | 65 #if defined(OS_BSD) || defined(OS_MACOSX) || defined(OS_NACL) |
66 static int CallStat(const char *path, stat_wrapper_t *sb) { | 66 static int CallStat(const char *path, stat_wrapper_t *sb) { |
67 ThreadRestrictions::AssertIOAllowed(); | 67 ThreadRestrictions::AssertIOAllowed(); |
68 return stat(path, sb); | 68 return stat(path, sb); |
69 } | 69 } |
70 static int CallLstat(const char *path, stat_wrapper_t *sb) { | 70 static int CallLstat(const char *path, stat_wrapper_t *sb) { |
71 ThreadRestrictions::AssertIOAllowed(); | 71 ThreadRestrictions::AssertIOAllowed(); |
72 return lstat(path, sb); | 72 return lstat(path, sb); |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 << current.value(); | 341 << current.value(); |
342 } | 342 } |
343 | 343 |
344 current = traversal.Next(); | 344 current = traversal.Next(); |
345 if (!current.empty()) | 345 if (!current.empty()) |
346 from_stat = traversal.GetInfo().stat(); | 346 from_stat = traversal.GetInfo().stat(); |
347 } | 347 } |
348 | 348 |
349 return success; | 349 return success; |
350 } | 350 } |
351 #endif // !defined(__native_client_nonsfi__) | 351 #endif // !defined(OS_NACL_NONSFI) |
352 | 352 |
353 bool PathExists(const FilePath& path) { | 353 bool PathExists(const FilePath& path) { |
354 ThreadRestrictions::AssertIOAllowed(); | 354 ThreadRestrictions::AssertIOAllowed(); |
355 #if defined(OS_ANDROID) | 355 #if defined(OS_ANDROID) |
356 if (path.IsContentUri()) { | 356 if (path.IsContentUri()) { |
357 return ContentUriExists(path); | 357 return ContentUriExists(path); |
358 } | 358 } |
359 #endif | 359 #endif |
360 return access(path.value().c_str(), F_OK) == 0; | 360 return access(path.value().c_str(), F_OK) == 0; |
361 } | 361 } |
362 | 362 |
363 #if !defined(__native_client_nonsfi__) | 363 #if !defined(OS_NACL_NONSFI) |
364 bool PathIsWritable(const FilePath& path) { | 364 bool PathIsWritable(const FilePath& path) { |
365 ThreadRestrictions::AssertIOAllowed(); | 365 ThreadRestrictions::AssertIOAllowed(); |
366 return access(path.value().c_str(), W_OK) == 0; | 366 return access(path.value().c_str(), W_OK) == 0; |
367 } | 367 } |
368 | 368 |
369 bool DirectoryExists(const FilePath& path) { | 369 bool DirectoryExists(const FilePath& path) { |
370 ThreadRestrictions::AssertIOAllowed(); | 370 ThreadRestrictions::AssertIOAllowed(); |
371 stat_wrapper_t file_info; | 371 stat_wrapper_t file_info; |
372 if (CallStat(path.value().c_str(), &file_info) == 0) | 372 if (CallStat(path.value().c_str(), &file_info) == 0) |
373 return S_ISDIR(file_info.st_mode); | 373 return S_ISDIR(file_info.st_mode); |
374 return false; | 374 return false; |
375 } | 375 } |
376 #endif // !defined(__native_client_nonsfi__) | 376 #endif // !defined(OS_NACL_NONSFI) |
377 | 377 |
378 bool ReadFromFD(int fd, char* buffer, size_t bytes) { | 378 bool ReadFromFD(int fd, char* buffer, size_t bytes) { |
379 size_t total_read = 0; | 379 size_t total_read = 0; |
380 while (total_read < bytes) { | 380 while (total_read < bytes) { |
381 ssize_t bytes_read = | 381 ssize_t bytes_read = |
382 HANDLE_EINTR(read(fd, buffer + total_read, bytes - total_read)); | 382 HANDLE_EINTR(read(fd, buffer + total_read, bytes - total_read)); |
383 if (bytes_read <= 0) | 383 if (bytes_read <= 0) |
384 break; | 384 break; |
385 total_read += bytes_read; | 385 total_read += bytes_read; |
386 } | 386 } |
387 return total_read == bytes; | 387 return total_read == bytes; |
388 } | 388 } |
389 | 389 |
390 #if !defined(__native_client_nonsfi__) | 390 #if !defined(OS_NACL_NONSFI) |
391 bool CreateSymbolicLink(const FilePath& target_path, | 391 bool CreateSymbolicLink(const FilePath& target_path, |
392 const FilePath& symlink_path) { | 392 const FilePath& symlink_path) { |
393 DCHECK(!symlink_path.empty()); | 393 DCHECK(!symlink_path.empty()); |
394 DCHECK(!target_path.empty()); | 394 DCHECK(!target_path.empty()); |
395 return ::symlink(target_path.value().c_str(), | 395 return ::symlink(target_path.value().c_str(), |
396 symlink_path.value().c_str()) != -1; | 396 symlink_path.value().c_str()) != -1; |
397 } | 397 } |
398 | 398 |
399 bool ReadSymbolicLink(const FilePath& symlink_path, FilePath* target_path) { | 399 bool ReadSymbolicLink(const FilePath& symlink_path, FilePath* target_path) { |
400 DCHECK(!symlink_path.empty()); | 400 DCHECK(!symlink_path.empty()); |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 | 930 |
931 #endif // !defined(__native_client_nonsfi__) | 931 #endif // !defined(OS_NACL_NONSFI) |
932 } // namespace base | 932 } // namespace base |
OLD | NEW |