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 "ppapi/tests/test_file_io.h" | 5 #include "ppapi/tests/test_file_io.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <stdio.h> | 9 #include <stdio.h> |
10 #include <string.h> | 10 #include <string.h> |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 break; | 120 break; |
121 const std::vector<char>& output = callback.output(); | 121 const std::vector<char>& output = callback.output(); |
122 assert(rv == static_cast<int32_t>(output.size())); | 122 assert(rv == static_cast<int32_t>(output.size())); |
123 offset += rv; | 123 offset += rv; |
124 data->append(output.begin(), output.end()); | 124 data->append(output.begin(), output.end()); |
125 } | 125 } |
126 | 126 |
127 return PP_OK; | 127 return PP_OK; |
128 } | 128 } |
129 | 129 |
| 130 #if !defined(PPAPI_OS_WIN) |
130 bool ReadEntireFileFromFileHandle(int fd, std::string* data) { | 131 bool ReadEntireFileFromFileHandle(int fd, std::string* data) { |
131 if (lseek(fd, 0, SEEK_SET) < 0) | 132 if (lseek(fd, 0, SEEK_SET) < 0) |
132 return false; | 133 return false; |
133 data->clear(); | 134 data->clear(); |
134 | 135 |
135 int ret; | 136 int ret; |
136 do { | 137 do { |
137 char buf[8192]; | 138 char buf[8192]; |
138 ret = read(fd, buf, sizeof(buf)); | 139 ret = read(fd, buf, sizeof(buf)); |
139 if (ret > 0) | 140 if (ret > 0) |
140 data->append(buf, ret); | 141 data->append(buf, ret); |
141 } while (ret > 0); | 142 } while (ret > 0); |
142 return ret == 0; | 143 return ret == 0; |
143 } | 144 } |
| 145 #endif // !defined(PPAPI_OS_WIN) |
144 | 146 |
145 int32_t WriteEntireBuffer(PP_Instance instance, | 147 int32_t WriteEntireBuffer(PP_Instance instance, |
146 pp::FileIO* file_io, | 148 pp::FileIO* file_io, |
147 int32_t offset, | 149 int32_t offset, |
148 const std::string& data, | 150 const std::string& data, |
149 CallbackType callback_type) { | 151 CallbackType callback_type) { |
150 TestCompletionCallback callback(instance, callback_type); | 152 TestCompletionCallback callback(instance, callback_type); |
151 int32_t write_offset = offset; | 153 int32_t write_offset = offset; |
152 const char* buf = data.c_str(); | 154 const char* buf = data.c_str(); |
153 int32_t size = static_cast<int32_t>(data.size()); | 155 int32_t size = static_cast<int32_t>(data.size()); |
(...skipping 1204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1358 if ((invalid_combination && callback.result() == PP_OK) || | 1360 if ((invalid_combination && callback.result() == PP_OK) || |
1359 (!invalid_combination && | 1361 (!invalid_combination && |
1360 ((callback.result() == PP_OK) != create_if_doesnt_exist))) { | 1362 ((callback.result() == PP_OK) != create_if_doesnt_exist))) { |
1361 return ReportOpenError(open_flags); | 1363 return ReportOpenError(open_flags); |
1362 } | 1364 } |
1363 | 1365 |
1364 return std::string(); | 1366 return std::string(); |
1365 } | 1367 } |
1366 | 1368 |
1367 // TODO(viettrungluu): Test Close(). crbug.com/69457 | 1369 // TODO(viettrungluu): Test Close(). crbug.com/69457 |
OLD | NEW |