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 namespace { | 63 namespace { |
63 | 64 |
64 #if defined(OS_BSD) || defined(OS_MACOSX) || defined(OS_NACL) | 65 #if defined(OS_BSD) || defined(OS_MACOSX) || defined(OS_NACL) |
65 static int CallStat(const char *path, stat_wrapper_t *sb) { | 66 static int CallStat(const char *path, stat_wrapper_t *sb) { |
66 ThreadRestrictions::AssertIOAllowed(); | 67 ThreadRestrictions::AssertIOAllowed(); |
67 return stat(path, sb); | 68 return stat(path, sb); |
68 } | 69 } |
69 static int CallLstat(const char *path, stat_wrapper_t *sb) { | 70 static int CallLstat(const char *path, stat_wrapper_t *sb) { |
70 ThreadRestrictions::AssertIOAllowed(); | 71 ThreadRestrictions::AssertIOAllowed(); |
71 return lstat(path, sb); | 72 return lstat(path, sb); |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 << current.value(); | 339 << current.value(); |
339 } | 340 } |
340 | 341 |
341 current = traversal.Next(); | 342 current = traversal.Next(); |
342 if (!current.empty()) | 343 if (!current.empty()) |
343 from_stat = traversal.GetInfo().stat(); | 344 from_stat = traversal.GetInfo().stat(); |
344 } | 345 } |
345 | 346 |
346 return success; | 347 return success; |
347 } | 348 } |
| 349 #endif // !defined(__native_client_nonsfi__) |
348 | 350 |
349 bool PathExists(const FilePath& path) { | 351 bool PathExists(const FilePath& path) { |
350 ThreadRestrictions::AssertIOAllowed(); | 352 ThreadRestrictions::AssertIOAllowed(); |
351 #if defined(OS_ANDROID) | 353 #if defined(OS_ANDROID) |
352 if (path.IsContentUri()) { | 354 if (path.IsContentUri()) { |
353 return ContentUriExists(path); | 355 return ContentUriExists(path); |
354 } | 356 } |
355 #endif | 357 #endif |
356 return access(path.value().c_str(), F_OK) == 0; | 358 return access(path.value().c_str(), F_OK) == 0; |
357 } | 359 } |
358 | 360 |
| 361 #if !defined(__native_client_nonsfi__) |
359 bool PathIsWritable(const FilePath& path) { | 362 bool PathIsWritable(const FilePath& path) { |
360 ThreadRestrictions::AssertIOAllowed(); | 363 ThreadRestrictions::AssertIOAllowed(); |
361 return access(path.value().c_str(), W_OK) == 0; | 364 return access(path.value().c_str(), W_OK) == 0; |
362 } | 365 } |
363 | 366 |
364 bool DirectoryExists(const FilePath& path) { | 367 bool DirectoryExists(const FilePath& path) { |
365 ThreadRestrictions::AssertIOAllowed(); | 368 ThreadRestrictions::AssertIOAllowed(); |
366 stat_wrapper_t file_info; | 369 stat_wrapper_t file_info; |
367 if (CallStat(path.value().c_str(), &file_info) == 0) | 370 if (CallStat(path.value().c_str(), &file_info) == 0) |
368 return S_ISDIR(file_info.st_mode); | 371 return S_ISDIR(file_info.st_mode); |
369 return false; | 372 return false; |
370 } | 373 } |
| 374 #endif // !defined(__native_client_nonsfi__) |
371 | 375 |
372 bool ReadFromFD(int fd, char* buffer, size_t bytes) { | 376 bool ReadFromFD(int fd, char* buffer, size_t bytes) { |
373 size_t total_read = 0; | 377 size_t total_read = 0; |
374 while (total_read < bytes) { | 378 while (total_read < bytes) { |
375 ssize_t bytes_read = | 379 ssize_t bytes_read = |
376 HANDLE_EINTR(read(fd, buffer + total_read, bytes - total_read)); | 380 HANDLE_EINTR(read(fd, buffer + total_read, bytes - total_read)); |
377 if (bytes_read <= 0) | 381 if (bytes_read <= 0) |
378 break; | 382 break; |
379 total_read += bytes_read; | 383 total_read += bytes_read; |
380 } | 384 } |
381 return total_read == bytes; | 385 return total_read == bytes; |
382 } | 386 } |
383 | 387 |
| 388 #if !defined(__native_client_nonsfi__) |
384 bool CreateSymbolicLink(const FilePath& target_path, | 389 bool CreateSymbolicLink(const FilePath& target_path, |
385 const FilePath& symlink_path) { | 390 const FilePath& symlink_path) { |
386 DCHECK(!symlink_path.empty()); | 391 DCHECK(!symlink_path.empty()); |
387 DCHECK(!target_path.empty()); | 392 DCHECK(!target_path.empty()); |
388 return ::symlink(target_path.value().c_str(), | 393 return ::symlink(target_path.value().c_str(), |
389 symlink_path.value().c_str()) != -1; | 394 symlink_path.value().c_str()) != -1; |
390 } | 395 } |
391 | 396 |
392 bool ReadSymbolicLink(const FilePath& symlink_path, FilePath* target_path) { | 397 bool ReadSymbolicLink(const FilePath& symlink_path, FilePath* target_path) { |
393 DCHECK(!symlink_path.empty()); | 398 DCHECK(!symlink_path.empty()); |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
913 if (IGNORE_EINTR(close(infile)) < 0) | 918 if (IGNORE_EINTR(close(infile)) < 0) |
914 result = false; | 919 result = false; |
915 if (IGNORE_EINTR(close(outfile)) < 0) | 920 if (IGNORE_EINTR(close(outfile)) < 0) |
916 result = false; | 921 result = false; |
917 | 922 |
918 return result; | 923 return result; |
919 } | 924 } |
920 #endif // !defined(OS_MACOSX) | 925 #endif // !defined(OS_MACOSX) |
921 | 926 |
922 } // namespace internal | 927 } // namespace internal |
| 928 |
| 929 #endif // !defined(__native_client_nonsfi__) |
923 } // namespace base | 930 } // namespace base |
OLD | NEW |