OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 DeleteArray(result); | 175 DeleteArray(result); |
176 return NULL; | 176 return NULL; |
177 } | 177 } |
178 i += read; | 178 i += read; |
179 } | 179 } |
180 fclose(file); | 180 fclose(file); |
181 return result; | 181 return result; |
182 } | 182 } |
183 | 183 |
184 | 184 |
185 char* ReadChars(const char* filename, int* size, bool verbose) { | 185 byte* ReadBytes(const char* filename, int* size, bool verbose) { |
186 return ReadCharsFromFile(filename, size, 0, verbose); | 186 char* chars = ReadCharsFromFile(filename, size, 0, verbose); |
| 187 return reinterpret_cast<byte*>(chars); |
187 } | 188 } |
188 | 189 |
189 | 190 |
190 Vector<const char> ReadFile(const char* filename, | 191 Vector<const char> ReadFile(const char* filename, |
191 bool* exists, | 192 bool* exists, |
192 bool verbose) { | 193 bool verbose) { |
193 int size; | 194 int size; |
194 char* result = ReadCharsFromFile(filename, &size, 1, verbose); | 195 char* result = ReadCharsFromFile(filename, &size, 1, verbose); |
195 if (!result) { | 196 if (!result) { |
196 *exists = false; | 197 *exists = false; |
(...skipping 29 matching lines...) Expand all Loading... |
226 OS::PrintError("Cannot open file %s for reading.\n", filename); | 227 OS::PrintError("Cannot open file %s for reading.\n", filename); |
227 } | 228 } |
228 return 0; | 229 return 0; |
229 } | 230 } |
230 int written = WriteCharsToFile(str, size, f); | 231 int written = WriteCharsToFile(str, size, f); |
231 fclose(f); | 232 fclose(f); |
232 return written; | 233 return written; |
233 } | 234 } |
234 | 235 |
235 | 236 |
| 237 int WriteBytes(const char* filename, |
| 238 const byte* bytes, |
| 239 int size, |
| 240 bool verbose) { |
| 241 const char* str = reinterpret_cast<const char*>(bytes); |
| 242 return WriteChars(filename, str, size, verbose); |
| 243 } |
| 244 |
| 245 |
236 StringBuilder::StringBuilder(int size) { | 246 StringBuilder::StringBuilder(int size) { |
237 buffer_ = Vector<char>::New(size); | 247 buffer_ = Vector<char>::New(size); |
238 position_ = 0; | 248 position_ = 0; |
239 } | 249 } |
240 | 250 |
241 | 251 |
242 void StringBuilder::AddString(const char* s) { | 252 void StringBuilder::AddString(const char* s) { |
243 AddSubstring(s, strlen(s)); | 253 AddSubstring(s, strlen(s)); |
244 } | 254 } |
245 | 255 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 buffer_[position_] = '\0'; | 288 buffer_[position_] = '\0'; |
279 // Make sure nobody managed to add a 0-character to the | 289 // Make sure nobody managed to add a 0-character to the |
280 // buffer while building the string. | 290 // buffer while building the string. |
281 ASSERT(strlen(buffer_.start()) == static_cast<size_t>(position_)); | 291 ASSERT(strlen(buffer_.start()) == static_cast<size_t>(position_)); |
282 position_ = -1; | 292 position_ = -1; |
283 ASSERT(is_finalized()); | 293 ASSERT(is_finalized()); |
284 return buffer_.start(); | 294 return buffer_.start(); |
285 } | 295 } |
286 | 296 |
287 } } // namespace v8::internal | 297 } } // namespace v8::internal |
OLD | NEW |