OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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> |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
366 while (total_read < bytes) { | 366 while (total_read < bytes) { |
367 ssize_t bytes_read = | 367 ssize_t bytes_read = |
368 HANDLE_EINTR(read(fd, buffer + total_read, bytes - total_read)); | 368 HANDLE_EINTR(read(fd, buffer + total_read, bytes - total_read)); |
369 if (bytes_read <= 0) | 369 if (bytes_read <= 0) |
370 break; | 370 break; |
371 total_read += bytes_read; | 371 total_read += bytes_read; |
372 } | 372 } |
373 return total_read == bytes; | 373 return total_read == bytes; |
374 } | 374 } |
375 | 375 |
376 bool CreateSymbolicLink(const FilePath& target_path, | |
377 const FilePath& symlink_path) { | |
378 DCHECK(!symlink_path.empty()); | |
379 DCHECK(!target_path.empty()); | |
380 return ::symlink(target_path.value().c_str(), | |
381 symlink_path.value().c_str()) != -1; | |
382 } | |
383 | |
384 bool ReadSymbolicLink(const FilePath& symlink_path, | |
385 FilePath* target_path) { | |
386 DCHECK(!symlink_path.empty()); | |
387 DCHECK(target_path); | |
388 char buf[PATH_MAX]; | |
389 ssize_t count = ::readlink(symlink_path.value().c_str(), buf, arraysize(buf)); | |
390 if (count > 0) { | |
Evan Martin
2010/11/29 21:21:14
Consider an early return pattern here instead (if
Greg Spencer (Chromium)
2010/11/29 21:34:11
Done.
| |
391 *target_path = FilePath(FilePath::StringType(buf, count)); | |
Evan Martin
2010/11/29 21:21:14
Can use std::string here, since we know the string
Greg Spencer (Chromium)
2010/11/29 21:34:11
I prefer to use the actual type that FilePath expe
| |
392 } else { | |
393 return false; | |
394 } | |
395 return true; | |
396 } | |
397 | |
376 // Creates and opens a temporary file in |directory|, returning the | 398 // Creates and opens a temporary file in |directory|, returning the |
377 // file descriptor. |path| is set to the temporary file path. | 399 // file descriptor. |path| is set to the temporary file path. |
378 // This function does NOT unlink() the file. | 400 // This function does NOT unlink() the file. |
379 int CreateAndOpenFdForTemporaryFile(FilePath directory, FilePath* path) { | 401 int CreateAndOpenFdForTemporaryFile(FilePath directory, FilePath* path) { |
380 base::ThreadRestrictions::AssertIOAllowed(); // For call to mkstemp(). | 402 base::ThreadRestrictions::AssertIOAllowed(); // For call to mkstemp(). |
381 *path = directory.Append(kTempFileName); | 403 *path = directory.Append(kTempFileName); |
382 const std::string& tmpdir_string = path->value(); | 404 const std::string& tmpdir_string = path->value(); |
383 // this should be OK since mkstemp just replaces characters in place | 405 // this should be OK since mkstemp just replaces characters in place |
384 char* buffer = const_cast<char*>(tmpdir_string.c_str()); | 406 char* buffer = const_cast<char*>(tmpdir_string.c_str()); |
385 | 407 |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
857 if (HANDLE_EINTR(close(infile)) < 0) | 879 if (HANDLE_EINTR(close(infile)) < 0) |
858 result = false; | 880 result = false; |
859 if (HANDLE_EINTR(close(outfile)) < 0) | 881 if (HANDLE_EINTR(close(outfile)) < 0) |
860 result = false; | 882 result = false; |
861 | 883 |
862 return result; | 884 return result; |
863 } | 885 } |
864 #endif // defined(OS_MACOSX) | 886 #endif // defined(OS_MACOSX) |
865 | 887 |
866 } // namespace file_util | 888 } // namespace file_util |
OLD | NEW |