| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 // files, not filenames). This function does NOT unlink() the file. | 380 // files, not filenames). This function does NOT unlink() the file. |
| 381 int CreateAndOpenFdForTemporaryFile(FilePath directory, FilePath* path) { | 381 int CreateAndOpenFdForTemporaryFile(FilePath directory, FilePath* path) { |
| 382 *path = directory.Append(kTempFileName); | 382 *path = directory.Append(kTempFileName); |
| 383 const std::string& tmpdir_string = path->value(); | 383 const std::string& tmpdir_string = path->value(); |
| 384 // this should be OK since mkstemp just replaces characters in place | 384 // this should be OK since mkstemp just replaces characters in place |
| 385 char* buffer = const_cast<char*>(tmpdir_string.c_str()); | 385 char* buffer = const_cast<char*>(tmpdir_string.c_str()); |
| 386 | 386 |
| 387 return mkstemp(buffer); | 387 return mkstemp(buffer); |
| 388 } | 388 } |
| 389 | 389 |
| 390 bool CreateTemporaryFileName(FilePath* path) { | 390 bool CreateTemporaryFile(FilePath* path) { |
| 391 FilePath directory; | 391 FilePath directory; |
| 392 if (!GetTempDir(&directory)) | 392 if (!GetTempDir(&directory)) |
| 393 return false; | 393 return false; |
| 394 int fd = CreateAndOpenFdForTemporaryFile(directory, path); | 394 int fd = CreateAndOpenFdForTemporaryFile(directory, path); |
| 395 if (fd < 0) | 395 if (fd < 0) |
| 396 return false; | 396 return false; |
| 397 close(fd); | 397 close(fd); |
| 398 return true; | 398 return true; |
| 399 } | 399 } |
| 400 | 400 |
| 401 FILE* CreateAndOpenTemporaryShmemFile(FilePath* path) { | 401 FILE* CreateAndOpenTemporaryShmemFile(FilePath* path) { |
| 402 FilePath directory; | 402 FilePath directory; |
| 403 if (!GetShmemTempDir(&directory)) | 403 if (!GetShmemTempDir(&directory)) |
| 404 return false; | 404 return false; |
| 405 | 405 |
| 406 return CreateAndOpenTemporaryFileInDir(directory, path); | 406 return CreateAndOpenTemporaryFileInDir(directory, path); |
| 407 } | 407 } |
| 408 | 408 |
| 409 FILE* CreateAndOpenTemporaryFileInDir(const FilePath& dir, FilePath* path) { | 409 FILE* CreateAndOpenTemporaryFileInDir(const FilePath& dir, FilePath* path) { |
| 410 int fd = CreateAndOpenFdForTemporaryFile(dir, path); | 410 int fd = CreateAndOpenFdForTemporaryFile(dir, path); |
| 411 if (fd < 0) | 411 if (fd < 0) |
| 412 return NULL; | 412 return NULL; |
| 413 | 413 |
| 414 return fdopen(fd, "a+"); | 414 return fdopen(fd, "a+"); |
| 415 } | 415 } |
| 416 | 416 // TODO(port): implement me. |
| 417 bool CreateTemporaryFileNameInDir(const std::wstring& dir, | 417 bool CreateTemporaryFileInDir(const FilePath& dir, |
| 418 std::wstring* temp_file) { | 418 FilePath* temp_file) { |
| 419 // Not implemented yet. | |
| 420 NOTREACHED(); | 419 NOTREACHED(); |
| 421 return false; | 420 return false; |
| 422 } | 421 } |
| 423 | 422 |
| 424 bool CreateNewTempDirectory(const FilePath::StringType& prefix, | 423 bool CreateNewTempDirectory(const FilePath::StringType& prefix, |
| 425 FilePath* new_temp_path) { | 424 FilePath* new_temp_path) { |
| 426 FilePath tmpdir; | 425 FilePath tmpdir; |
| 427 if (!GetTempDir(&tmpdir)) | 426 if (!GetTempDir(&tmpdir)) |
| 428 return false; | 427 return false; |
| 429 tmpdir = tmpdir.Append(kTempFileName); | 428 tmpdir = tmpdir.Append(kTempFileName); |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 munmap(data_, length_); | 720 munmap(data_, length_); |
| 722 if (file_ != -1) | 721 if (file_ != -1) |
| 723 close(file_); | 722 close(file_); |
| 724 | 723 |
| 725 data_ = NULL; | 724 data_ = NULL; |
| 726 length_ = 0; | 725 length_ = 0; |
| 727 file_ = -1; | 726 file_ = -1; |
| 728 } | 727 } |
| 729 | 728 |
| 730 } // namespace file_util | 729 } // namespace file_util |
| OLD | NEW |