| 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 // 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 <errno.h> | 5 #include <errno.h> |
| 6 #include <signal.h> | 6 #include <signal.h> |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 | 8 |
| 9 #include "src/v8.h" | 9 #include "src/v8.h" |
| 10 | 10 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 111 |
| 112 char* GetExtraCode(char* filename) { | 112 char* GetExtraCode(char* filename) { |
| 113 if (filename == NULL || strlen(filename) == 0) return NULL; | 113 if (filename == NULL || strlen(filename) == 0) return NULL; |
| 114 ::printf("Embedding extra script: %s\n", filename); | 114 ::printf("Embedding extra script: %s\n", filename); |
| 115 FILE* file = base::OS::FOpen(filename, "rb"); | 115 FILE* file = base::OS::FOpen(filename, "rb"); |
| 116 if (file == NULL) { | 116 if (file == NULL) { |
| 117 fprintf(stderr, "Failed to open '%s': errno %d\n", filename, errno); | 117 fprintf(stderr, "Failed to open '%s': errno %d\n", filename, errno); |
| 118 exit(1); | 118 exit(1); |
| 119 } | 119 } |
| 120 fseek(file, 0, SEEK_END); | 120 fseek(file, 0, SEEK_END); |
| 121 int size = ftell(file); | 121 size_t size = ftell(file); |
| 122 rewind(file); | 122 rewind(file); |
| 123 char* chars = new char[size + 1]; | 123 char* chars = new char[size + 1]; |
| 124 chars[size] = '\0'; | 124 chars[size] = '\0'; |
| 125 for (int i = 0; i < size;) { | 125 for (size_t i = 0; i < size;) { |
| 126 int read = static_cast<int>(fread(&chars[i], 1, size - i, file)); | 126 size_t read = fread(&chars[i], 1, size - i, file); |
| 127 if (read < 0) { | 127 if (ferror(file)) { |
| 128 fprintf(stderr, "Failed to read '%s': errno %d\n", filename, errno); | 128 fprintf(stderr, "Failed to read '%s': errno %d\n", filename, errno); |
| 129 exit(1); | 129 exit(1); |
| 130 } | 130 } |
| 131 i += read; | 131 i += read; |
| 132 } | 132 } |
| 133 fclose(file); | 133 fclose(file); |
| 134 return chars; | 134 return chars; |
| 135 } | 135 } |
| 136 | 136 |
| 137 | 137 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 164 writer.WriteSnapshot(blob); | 164 writer.WriteSnapshot(blob); |
| 165 delete[] extra_code; | 165 delete[] extra_code; |
| 166 delete[] blob.data; | 166 delete[] blob.data; |
| 167 } | 167 } |
| 168 | 168 |
| 169 V8::Dispose(); | 169 V8::Dispose(); |
| 170 V8::ShutdownPlatform(); | 170 V8::ShutdownPlatform(); |
| 171 delete platform; | 171 delete platform; |
| 172 return 0; | 172 return 0; |
| 173 } | 173 } |
| OLD | NEW |