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/eintr_wrappers.h" |
12 #include "base/file_path.h" | 13 #include "base/file_path.h" |
13 #include "base/string_util.h" | 14 #include "base/string_util.h" |
14 | 15 |
15 namespace file_util { | 16 namespace file_util { |
16 | 17 |
17 bool GetTempDir(FilePath* path) { | 18 bool GetTempDir(FilePath* path) { |
18 const char* tmp = getenv("TMPDIR"); | 19 const char* tmp = getenv("TMPDIR"); |
19 if (tmp) | 20 if (tmp) |
20 *path = FilePath(tmp); | 21 *path = FilePath(tmp); |
21 else | 22 else |
(...skipping 15 matching lines...) Expand all Loading... |
37 if (outfile < 0) { | 38 if (outfile < 0) { |
38 close(infile); | 39 close(infile); |
39 return false; | 40 return false; |
40 } | 41 } |
41 | 42 |
42 const size_t kBufferSize = 32768; | 43 const size_t kBufferSize = 32768; |
43 std::vector<char> buffer(kBufferSize); | 44 std::vector<char> buffer(kBufferSize); |
44 bool result = true; | 45 bool result = true; |
45 | 46 |
46 while (result) { | 47 while (result) { |
47 ssize_t bytes_read = read(infile, &buffer[0], buffer.size()); | 48 ssize_t bytes_read = HANDLE_EINTR(read(infile, &buffer[0], buffer.size())); |
48 if (bytes_read < 0) { | 49 if (bytes_read < 0) { |
49 result = false; | 50 result = false; |
50 break; | 51 break; |
51 } | 52 } |
52 if (bytes_read == 0) | 53 if (bytes_read == 0) |
53 break; | 54 break; |
54 // Allow for partial writes | 55 // Allow for partial writes |
55 ssize_t bytes_written_per_read = 0; | 56 ssize_t bytes_written_per_read = 0; |
56 do { | 57 do { |
57 ssize_t bytes_written_partial = write( | 58 ssize_t bytes_written_partial = HANDLE_EINTR(write( |
58 outfile, | 59 outfile, |
59 &buffer[bytes_written_per_read], | 60 &buffer[bytes_written_per_read], |
60 bytes_read - bytes_written_per_read); | 61 bytes_read - bytes_written_per_read)); |
61 if (bytes_written_partial < 0) { | 62 if (bytes_written_partial < 0) { |
62 result = false; | 63 result = false; |
63 break; | 64 break; |
64 } | 65 } |
65 bytes_written_per_read += bytes_written_partial; | 66 bytes_written_per_read += bytes_written_partial; |
66 } while (bytes_written_per_read < bytes_read); | 67 } while (bytes_written_per_read < bytes_read); |
67 } | 68 } |
68 | 69 |
69 if (close(infile) < 0) | 70 if (HANDLE_EINTR(close(infile)) < 0) |
70 result = false; | 71 result = false; |
71 if (close(outfile) < 0) | 72 if (HANDLE_EINTR(close(outfile)) < 0) |
72 result = false; | 73 result = false; |
73 | 74 |
74 return result; | 75 return result; |
75 } | 76 } |
76 | 77 |
77 } // namespace file_util | 78 } // namespace file_util |
OLD | NEW |