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 <mach/mach.h> | 9 #include <mach/mach.h> |
10 #include <mach/clock.h> | 10 #include <mach/clock.h> |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 | 143 |
144 | 144 |
145 void OS::Print(const char* format, ...) { | 145 void OS::Print(const char* format, ...) { |
146 va_list args; | 146 va_list args; |
147 va_start(args, format); | 147 va_start(args, format); |
148 VFPrint(stdout, format, args); | 148 VFPrint(stdout, format, args); |
149 va_end(args); | 149 va_end(args); |
150 } | 150 } |
151 | 151 |
152 | 152 |
| 153 void OS::FPrint(FILE* stream, const char* format, ...) { |
| 154 va_list args; |
| 155 va_start(args, format); |
| 156 VFPrint(stream, format, args); |
| 157 va_end(args); |
| 158 } |
| 159 |
| 160 |
153 void OS::VFPrint(FILE* stream, const char* format, va_list args) { | 161 void OS::VFPrint(FILE* stream, const char* format, va_list args) { |
154 vfprintf(stream, format, args); | 162 vfprintf(stream, format, args); |
155 fflush(stream); | 163 fflush(stream); |
156 } | 164 } |
157 | 165 |
158 | 166 |
159 int OS::SNPrint(char* str, size_t size, const char* format, ...) { | 167 int OS::SNPrint(char* str, size_t size, const char* format, ...) { |
160 va_list args; | 168 va_list args; |
161 va_start(args, format); | 169 va_start(args, format); |
162 int retval = VSNPrint(str, size, format, args); | 170 int retval = VSNPrint(str, size, format, args); |
163 va_end(args); | 171 va_end(args); |
164 return retval; | 172 return retval; |
165 } | 173 } |
166 | 174 |
167 | 175 |
168 int OS::VSNPrint(char* str, size_t size, const char* format, va_list args) { | 176 int OS::VSNPrint(char* str, size_t size, const char* format, va_list args) { |
169 return vsnprintf(str, size, format, args); | 177 return vsnprintf(str, size, format, args); |
170 } | 178 } |
171 | 179 |
172 | 180 |
173 void OS::PrintErr(const char* format, ...) { | 181 void OS::PrintErr(const char* format, ...) { |
174 va_list args; | 182 va_list args; |
175 va_start(args, format); | 183 va_start(args, format); |
176 VFPrint(stderr, format, args); | 184 VFPrint(stderr, format, args); |
177 va_end(args); | 185 va_end(args); |
178 } | 186 } |
179 | 187 |
180 | 188 |
| 189 FILE* OS::FOpen(const char* path, const char* mode) { |
| 190 FILE* file = fopen(path, mode); |
| 191 if (file == NULL) return NULL; |
| 192 return file; |
| 193 } |
| 194 |
| 195 |
181 void OS::InitOnce() { | 196 void OS::InitOnce() { |
182 // TODO(5411554): For now we check that initonce is called only once, | 197 // TODO(5411554): For now we check that initonce is called only once, |
183 // Once there is more formal mechanism to call InitOnce we can move | 198 // Once there is more formal mechanism to call InitOnce we can move |
184 // this check there. | 199 // this check there. |
185 static bool init_once_called = false; | 200 static bool init_once_called = false; |
186 ASSERT(init_once_called == false); | 201 ASSERT(init_once_called == false); |
187 init_once_called = true; | 202 init_once_called = true; |
188 } | 203 } |
189 | 204 |
190 | 205 |
191 void OS::Shutdown() { | 206 void OS::Shutdown() { |
192 } | 207 } |
193 | 208 |
194 | 209 |
195 void OS::Abort() { | 210 void OS::Abort() { |
196 abort(); | 211 abort(); |
197 } | 212 } |
198 | 213 |
199 | 214 |
200 void OS::Exit(int code) { | 215 void OS::Exit(int code) { |
201 exit(code); | 216 exit(code); |
202 } | 217 } |
203 | 218 |
204 } // namespace dart | 219 } // namespace dart |
OLD | NEW |