| 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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 } | 307 } |
| 308 | 308 |
| 309 return success; | 309 return success; |
| 310 } | 310 } |
| 311 | 311 |
| 312 bool PathExists(const FilePath& path) { | 312 bool PathExists(const FilePath& path) { |
| 313 ThreadRestrictions::AssertIOAllowed(); | 313 ThreadRestrictions::AssertIOAllowed(); |
| 314 return access(path.value().c_str(), F_OK) == 0; | 314 return access(path.value().c_str(), F_OK) == 0; |
| 315 } | 315 } |
| 316 | 316 |
| 317 bool PathIsWritable(const FilePath& path) { |
| 318 ThreadRestrictions::AssertIOAllowed(); |
| 319 return access(path.value().c_str(), W_OK) == 0; |
| 320 } |
| 321 |
| 322 bool DirectoryExists(const FilePath& path) { |
| 323 ThreadRestrictions::AssertIOAllowed(); |
| 324 stat_wrapper_t file_info; |
| 325 if (CallStat(path.value().c_str(), &file_info) == 0) |
| 326 return S_ISDIR(file_info.st_mode); |
| 327 return false; |
| 328 } |
| 329 |
| 317 } // namespace base | 330 } // namespace base |
| 318 | 331 |
| 319 // ----------------------------------------------------------------------------- | 332 // ----------------------------------------------------------------------------- |
| 320 | 333 |
| 321 namespace file_util { | 334 namespace file_util { |
| 322 | 335 |
| 323 using base::stat_wrapper_t; | 336 using base::stat_wrapper_t; |
| 324 using base::CallStat; | 337 using base::CallStat; |
| 325 using base::CallLstat; | 338 using base::CallLstat; |
| 339 using base::DirectoryExists; |
| 326 using base::FileEnumerator; | 340 using base::FileEnumerator; |
| 327 using base::FilePath; | 341 using base::FilePath; |
| 328 using base::MakeAbsoluteFilePath; | 342 using base::MakeAbsoluteFilePath; |
| 329 using base::RealPath; | 343 using base::RealPath; |
| 330 using base::VerifySpecificPathControlledByUser; | 344 using base::VerifySpecificPathControlledByUser; |
| 331 | 345 |
| 332 bool PathIsWritable(const FilePath& path) { | |
| 333 base::ThreadRestrictions::AssertIOAllowed(); | |
| 334 return access(path.value().c_str(), W_OK) == 0; | |
| 335 } | |
| 336 | |
| 337 bool DirectoryExists(const FilePath& path) { | |
| 338 base::ThreadRestrictions::AssertIOAllowed(); | |
| 339 stat_wrapper_t file_info; | |
| 340 if (CallStat(path.value().c_str(), &file_info) == 0) | |
| 341 return S_ISDIR(file_info.st_mode); | |
| 342 return false; | |
| 343 } | |
| 344 | |
| 345 bool ReadFromFD(int fd, char* buffer, size_t bytes) { | 346 bool ReadFromFD(int fd, char* buffer, size_t bytes) { |
| 346 size_t total_read = 0; | 347 size_t total_read = 0; |
| 347 while (total_read < bytes) { | 348 while (total_read < bytes) { |
| 348 ssize_t bytes_read = | 349 ssize_t bytes_read = |
| 349 HANDLE_EINTR(read(fd, buffer + total_read, bytes - total_read)); | 350 HANDLE_EINTR(read(fd, buffer + total_read, bytes - total_read)); |
| 350 if (bytes_read <= 0) | 351 if (bytes_read <= 0) |
| 351 break; | 352 break; |
| 352 total_read += bytes_read; | 353 total_read += bytes_read; |
| 353 } | 354 } |
| 354 return total_read == bytes; | 355 return total_read == bytes; |
| (...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 result = false; | 949 result = false; |
| 949 if (HANDLE_EINTR(close(outfile)) < 0) | 950 if (HANDLE_EINTR(close(outfile)) < 0) |
| 950 result = false; | 951 result = false; |
| 951 | 952 |
| 952 return result; | 953 return result; |
| 953 } | 954 } |
| 954 #endif // !defined(OS_MACOSX) | 955 #endif // !defined(OS_MACOSX) |
| 955 | 956 |
| 956 } // namespace internal | 957 } // namespace internal |
| 957 } // namespace base | 958 } // namespace base |
| OLD | NEW |