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 <fcntl.h> | 7 #include <fcntl.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
15 | 15 |
16 namespace file_util { | 16 namespace file_util { |
17 | 17 |
18 const wchar_t kPathSeparator = L'/'; | 18 const wchar_t kPathSeparator = L'/'; |
19 | 19 |
20 bool GetTempDir(FilePath* path) { | 20 bool GetTempDir(FilePath* path) { |
21 const char* tmp = getenv("TMPDIR"); | 21 const char* tmp = getenv("TMPDIR"); |
22 if (tmp) | 22 if (tmp) |
23 *path = FilePath(tmp); | 23 *path = FilePath(tmp); |
24 else | 24 else |
25 *path = FilePath("/tmp"); | 25 *path = FilePath("/tmp"); |
26 return true; | 26 return true; |
27 } | 27 } |
28 | 28 |
29 FILE* OpenFile(const FilePath& filename, const char* mode) { | |
30 return fopen(filename.value().c_str(), mode); | |
31 } | |
32 | |
33 bool CopyFile(const FilePath& from_path, const FilePath& to_path) { | 29 bool CopyFile(const FilePath& from_path, const FilePath& to_path) { |
34 int infile = open(from_path.value().c_str(), O_RDONLY); | 30 int infile = open(from_path.value().c_str(), O_RDONLY); |
35 if (infile < 0) | 31 if (infile < 0) |
36 return false; | 32 return false; |
37 | 33 |
38 int outfile = creat(to_path.value().c_str(), 0666); | 34 int outfile = creat(to_path.value().c_str(), 0666); |
39 if (outfile < 0) { | 35 if (outfile < 0) { |
40 close(infile); | 36 close(infile); |
41 return false; | 37 return false; |
42 } | 38 } |
(...skipping 27 matching lines...) Expand all Loading... |
70 | 66 |
71 if (close(infile) < 0) | 67 if (close(infile) < 0) |
72 result = false; | 68 result = false; |
73 if (close(outfile) < 0) | 69 if (close(outfile) < 0) |
74 result = false; | 70 result = false; |
75 | 71 |
76 return result; | 72 return result; |
77 } | 73 } |
78 | 74 |
79 } // namespace file_util | 75 } // namespace file_util |
OLD | NEW |