Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: src/utils.cc

Issue 358363002: Move platform abstraction to base library (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: updates Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project 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 <stdarg.h> 5 #include <stdarg.h>
6 #include <sys/stat.h> 6 #include <sys/stat.h>
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/checks.h" 10 #include "src/base/logging.h"
11 #include "src/platform.h" 11 #include "src/base/platform/platform.h"
12 #include "src/utils.h" 12 #include "src/utils.h"
13 13
14 namespace v8 { 14 namespace v8 {
15 namespace internal { 15 namespace internal {
16 16
17 17
18 SimpleStringBuilder::SimpleStringBuilder(int size) { 18 SimpleStringBuilder::SimpleStringBuilder(int size) {
19 buffer_ = Vector<char>::New(size); 19 buffer_ = Vector<char>::New(size);
20 position_ = 0; 20 position_ = 0;
21 } 21 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 ASSERT(strlen(buffer_.start()) == static_cast<size_t>(position_)); 73 ASSERT(strlen(buffer_.start()) == static_cast<size_t>(position_));
74 position_ = -1; 74 position_ = -1;
75 ASSERT(is_finalized()); 75 ASSERT(is_finalized());
76 return buffer_.start(); 76 return buffer_.start();
77 } 77 }
78 78
79 79
80 void PrintF(const char* format, ...) { 80 void PrintF(const char* format, ...) {
81 va_list arguments; 81 va_list arguments;
82 va_start(arguments, format); 82 va_start(arguments, format);
83 OS::VPrint(format, arguments); 83 base::OS::VPrint(format, arguments);
84 va_end(arguments); 84 va_end(arguments);
85 } 85 }
86 86
87 87
88 void PrintF(FILE* out, const char* format, ...) { 88 void PrintF(FILE* out, const char* format, ...) {
89 va_list arguments; 89 va_list arguments;
90 va_start(arguments, format); 90 va_start(arguments, format);
91 OS::VFPrint(out, format, arguments); 91 base::OS::VFPrint(out, format, arguments);
92 va_end(arguments); 92 va_end(arguments);
93 } 93 }
94 94
95 95
96 void PrintPID(const char* format, ...) { 96 void PrintPID(const char* format, ...) {
97 OS::Print("[%d] ", OS::GetCurrentProcessId()); 97 base::OS::Print("[%d] ", base::OS::GetCurrentProcessId());
98 va_list arguments; 98 va_list arguments;
99 va_start(arguments, format); 99 va_start(arguments, format);
100 OS::VPrint(format, arguments); 100 base::OS::VPrint(format, arguments);
101 va_end(arguments); 101 va_end(arguments);
102 } 102 }
103 103
104 104
105 int SNPrintF(Vector<char> str, const char* format, ...) { 105 int SNPrintF(Vector<char> str, const char* format, ...) {
106 va_list args; 106 va_list args;
107 va_start(args, format); 107 va_start(args, format);
108 int result = VSNPrintF(str, format, args); 108 int result = VSNPrintF(str, format, args);
109 va_end(args); 109 va_end(args);
110 return result; 110 return result;
111 } 111 }
112 112
113 113
114 int VSNPrintF(Vector<char> str, const char* format, va_list args) { 114 int VSNPrintF(Vector<char> str, const char* format, va_list args) {
115 return OS::VSNPrintF(str.start(), str.length(), format, args); 115 return base::OS::VSNPrintF(str.start(), str.length(), format, args);
116 } 116 }
117 117
118 118
119 void StrNCpy(Vector<char> dest, const char* src, size_t n) { 119 void StrNCpy(Vector<char> dest, const char* src, size_t n) {
120 OS::StrNCpy(dest.start(), dest.length(), src, n); 120 base::OS::StrNCpy(dest.start(), dest.length(), src, n);
121 } 121 }
122 122
123 123
124 void Flush(FILE* out) { 124 void Flush(FILE* out) {
125 fflush(out); 125 fflush(out);
126 } 126 }
127 127
128 128
129 char* ReadLine(const char* prompt) { 129 char* ReadLine(const char* prompt) {
130 char* result = NULL; 130 char* result = NULL;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 } 178 }
179 179
180 180
181 char* ReadCharsFromFile(FILE* file, 181 char* ReadCharsFromFile(FILE* file,
182 int* size, 182 int* size,
183 int extra_space, 183 int extra_space,
184 bool verbose, 184 bool verbose,
185 const char* filename) { 185 const char* filename) {
186 if (file == NULL || fseek(file, 0, SEEK_END) != 0) { 186 if (file == NULL || fseek(file, 0, SEEK_END) != 0) {
187 if (verbose) { 187 if (verbose) {
188 OS::PrintError("Cannot read from file %s.\n", filename); 188 base::OS::PrintError("Cannot read from file %s.\n", filename);
189 } 189 }
190 return NULL; 190 return NULL;
191 } 191 }
192 192
193 // Get the size of the file and rewind it. 193 // Get the size of the file and rewind it.
194 *size = ftell(file); 194 *size = ftell(file);
195 rewind(file); 195 rewind(file);
196 196
197 char* result = NewArray<char>(*size + extra_space); 197 char* result = NewArray<char>(*size + extra_space);
198 for (int i = 0; i < *size && feof(file) == 0;) { 198 for (int i = 0; i < *size && feof(file) == 0;) {
199 int read = static_cast<int>(fread(&result[i], 1, *size - i, file)); 199 int read = static_cast<int>(fread(&result[i], 1, *size - i, file));
200 if (read != (*size - i) && ferror(file) != 0) { 200 if (read != (*size - i) && ferror(file) != 0) {
201 fclose(file); 201 fclose(file);
202 DeleteArray(result); 202 DeleteArray(result);
203 return NULL; 203 return NULL;
204 } 204 }
205 i += read; 205 i += read;
206 } 206 }
207 return result; 207 return result;
208 } 208 }
209 209
210 210
211 char* ReadCharsFromFile(const char* filename, 211 char* ReadCharsFromFile(const char* filename,
212 int* size, 212 int* size,
213 int extra_space, 213 int extra_space,
214 bool verbose) { 214 bool verbose) {
215 FILE* file = OS::FOpen(filename, "rb"); 215 FILE* file = base::OS::FOpen(filename, "rb");
216 char* result = ReadCharsFromFile(file, size, extra_space, verbose, filename); 216 char* result = ReadCharsFromFile(file, size, extra_space, verbose, filename);
217 if (file != NULL) fclose(file); 217 if (file != NULL) fclose(file);
218 return result; 218 return result;
219 } 219 }
220 220
221 221
222 byte* ReadBytes(const char* filename, int* size, bool verbose) { 222 byte* ReadBytes(const char* filename, int* size, bool verbose) {
223 char* chars = ReadCharsFromFile(filename, size, 0, verbose); 223 char* chars = ReadCharsFromFile(filename, size, 0, verbose);
224 return reinterpret_cast<byte*>(chars); 224 return reinterpret_cast<byte*>(chars);
225 } 225 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 str += write; 267 str += write;
268 } 268 }
269 return total; 269 return total;
270 } 270 }
271 271
272 272
273 int AppendChars(const char* filename, 273 int AppendChars(const char* filename,
274 const char* str, 274 const char* str,
275 int size, 275 int size,
276 bool verbose) { 276 bool verbose) {
277 FILE* f = OS::FOpen(filename, "ab"); 277 FILE* f = base::OS::FOpen(filename, "ab");
278 if (f == NULL) { 278 if (f == NULL) {
279 if (verbose) { 279 if (verbose) {
280 OS::PrintError("Cannot open file %s for writing.\n", filename); 280 base::OS::PrintError("Cannot open file %s for writing.\n", filename);
281 } 281 }
282 return 0; 282 return 0;
283 } 283 }
284 int written = WriteCharsToFile(str, size, f); 284 int written = WriteCharsToFile(str, size, f);
285 fclose(f); 285 fclose(f);
286 return written; 286 return written;
287 } 287 }
288 288
289 289
290 int WriteChars(const char* filename, 290 int WriteChars(const char* filename,
291 const char* str, 291 const char* str,
292 int size, 292 int size,
293 bool verbose) { 293 bool verbose) {
294 FILE* f = OS::FOpen(filename, "wb"); 294 FILE* f = base::OS::FOpen(filename, "wb");
295 if (f == NULL) { 295 if (f == NULL) {
296 if (verbose) { 296 if (verbose) {
297 OS::PrintError("Cannot open file %s for writing.\n", filename); 297 base::OS::PrintError("Cannot open file %s for writing.\n", filename);
298 } 298 }
299 return 0; 299 return 0;
300 } 300 }
301 int written = WriteCharsToFile(str, size, f); 301 int written = WriteCharsToFile(str, size, f);
302 fclose(f); 302 fclose(f);
303 return written; 303 return written;
304 } 304 }
305 305
306 306
307 int WriteBytes(const char* filename, 307 int WriteBytes(const char* filename,
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 } 408 }
409 if (u.bits.exp == 0) { 409 if (u.bits.exp == 0) {
410 // Detect +0, and -0 for IEEE double precision floating point. 410 // Detect +0, and -0 for IEEE double precision floating point.
411 if ((u.bits.man_low | u.bits.man_high) == 0) return false; 411 if ((u.bits.man_low | u.bits.man_high) == 0) return false;
412 } 412 }
413 return true; 413 return true;
414 } 414 }
415 415
416 416
417 } } // namespace v8::internal 417 } } // namespace v8::internal
OLDNEW
« src/base/macros.h ('K') | « src/utils.h ('k') | src/utils/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698