OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/os.h" | 5 #include "vm/os.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <limits.h> | 8 #include <limits.h> |
9 #include <time.h> | 9 #include <time.h> |
10 #include <sys/resource.h> | 10 #include <sys/resource.h> |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 | 170 |
171 | 171 |
172 void OS::Print(const char* format, ...) { | 172 void OS::Print(const char* format, ...) { |
173 va_list args; | 173 va_list args; |
174 va_start(args, format); | 174 va_start(args, format); |
175 VFPrint(stdout, format, args); | 175 VFPrint(stdout, format, args); |
176 va_end(args); | 176 va_end(args); |
177 } | 177 } |
178 | 178 |
179 | 179 |
| 180 void OS::FPrint(FILE* stream, const char* format, ...) { |
| 181 va_list args; |
| 182 va_start(args, format); |
| 183 VFPrint(stream, format, args); |
| 184 va_end(args); |
| 185 } |
| 186 |
| 187 |
180 void OS::VFPrint(FILE* stream, const char* format, va_list args) { | 188 void OS::VFPrint(FILE* stream, const char* format, va_list args) { |
181 vfprintf(stream, format, args); | 189 vfprintf(stream, format, args); |
182 fflush(stream); | 190 fflush(stream); |
183 } | 191 } |
184 | 192 |
185 | 193 |
186 int OS::SNPrint(char* str, size_t size, const char* format, ...) { | 194 int OS::SNPrint(char* str, size_t size, const char* format, ...) { |
187 va_list args; | 195 va_list args; |
188 va_start(args, format); | 196 va_start(args, format); |
189 int retval = VSNPrint(str, size, format, args); | 197 int retval = VSNPrint(str, size, format, args); |
190 va_end(args); | 198 va_end(args); |
191 return retval; | 199 return retval; |
192 } | 200 } |
193 | 201 |
194 | 202 |
195 int OS::VSNPrint(char* str, size_t size, const char* format, va_list args) { | 203 int OS::VSNPrint(char* str, size_t size, const char* format, va_list args) { |
196 return vsnprintf(str, size, format, args); | 204 return vsnprintf(str, size, format, args); |
197 } | 205 } |
198 | 206 |
199 | 207 |
200 void OS::PrintErr(const char* format, ...) { | 208 void OS::PrintErr(const char* format, ...) { |
201 va_list args; | 209 va_list args; |
202 va_start(args, format); | 210 va_start(args, format); |
203 VFPrint(stderr, format, args); | 211 VFPrint(stderr, format, args); |
204 va_end(args); | 212 va_end(args); |
205 } | 213 } |
206 | 214 |
207 | 215 |
| 216 FILE* OS::FOpen(const char* path, const char* mode) { |
| 217 FILE* file = fopen(path, mode); |
| 218 if (file == NULL) return NULL; |
| 219 return file; |
| 220 } |
| 221 |
| 222 |
208 void OS::InitOnce() { | 223 void OS::InitOnce() { |
209 // TODO(5411554): For now we check that initonce is called only once, | 224 // TODO(5411554): For now we check that initonce is called only once, |
210 // Once there is more formal mechanism to call InitOnce we can move | 225 // Once there is more formal mechanism to call InitOnce we can move |
211 // this check there. | 226 // this check there. |
212 static bool init_once_called = false; | 227 static bool init_once_called = false; |
213 ASSERT(init_once_called == false); | 228 ASSERT(init_once_called == false); |
214 init_once_called = true; | 229 init_once_called = true; |
215 } | 230 } |
216 | 231 |
217 | 232 |
218 void OS::Shutdown() { | 233 void OS::Shutdown() { |
219 } | 234 } |
220 | 235 |
221 | 236 |
222 void OS::Abort() { | 237 void OS::Abort() { |
223 abort(); | 238 abort(); |
224 } | 239 } |
225 | 240 |
226 | 241 |
227 void OS::Exit(int code) { | 242 void OS::Exit(int code) { |
228 exit(code); | 243 exit(code); |
229 } | 244 } |
230 | 245 |
231 } // namespace dart | 246 } // namespace dart |
OLD | NEW |