Chromium Code Reviews| 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 <time.h> | 7 #include <time.h> |
| 8 | 8 |
| 9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
| 10 | 10 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 | 153 |
| 154 int OS::SNPrint(char* str, size_t size, const char* format, ...) { | 154 int OS::SNPrint(char* str, size_t size, const char* format, ...) { |
| 155 va_list args; | 155 va_list args; |
| 156 va_start(args, format); | 156 va_start(args, format); |
| 157 int retval = VSNPrint(str, size, format, args); | 157 int retval = VSNPrint(str, size, format, args); |
| 158 va_end(args); | 158 va_end(args); |
| 159 return retval; | 159 return retval; |
| 160 } | 160 } |
| 161 | 161 |
| 162 | 162 |
| 163 #ifndef va_copy | |
|
Ivan Posva
2012/04/17 18:54:44
The only question I have is whether we should move
siva
2012/04/17 23:55:00
Will move it once we run into that issue again. Fo
| |
| 164 #define va_copy(dst, src) (memmove(&(dst), &(src), sizeof(dst))) | |
| 165 #endif /* va_copy */ | |
| 166 | |
| 167 | |
| 163 int OS::VSNPrint(char* str, size_t size, const char* format, va_list args) { | 168 int OS::VSNPrint(char* str, size_t size, const char* format, va_list args) { |
| 164 if (str == NULL || size == 0) { | 169 if (str == NULL || size == 0) { |
| 165 return _vscprintf(format, args); | 170 return _vscprintf(format, args); |
| 166 } | 171 } |
| 167 int written =_vsnprintf(str, size, format, args); | 172 va_list args_copy; |
| 173 va_copy(args_copy, args); | |
| 174 int written =_vsnprintf(str, size, format, args_copy); | |
| 175 va_end(args_copy); | |
| 168 if (written < 0) { | 176 if (written < 0) { |
| 169 // _vsnprintf returns -1 if the number of characters to be written is | 177 // _vsnprintf returns -1 if the number of characters to be written is |
| 170 // larger than 'size', so we call _vscprintf which returns the number | 178 // larger than 'size', so we call _vscprintf which returns the number |
| 171 // of characters that would have been written. | 179 // of characters that would have been written. |
| 172 written = _vscprintf(format, args); | 180 va_list args_retry; |
| 181 va_copy(args_retry, args); | |
| 182 written = _vscprintf(format, args_retry); | |
| 183 va_end(args_retry); | |
| 173 } | 184 } |
| 174 // Make sure to zero-terminate the string if the output was | 185 // Make sure to zero-terminate the string if the output was |
| 175 // truncated or if there was an error. | 186 // truncated or if there was an error. |
| 176 if (written >= size) { | 187 if (written >= size) { |
| 177 str[size - 1] = '\0'; | 188 str[size - 1] = '\0'; |
| 178 } | 189 } |
| 179 return written; | 190 return written; |
| 180 } | 191 } |
| 181 | 192 |
| 182 | 193 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 207 void OS::Abort() { | 218 void OS::Abort() { |
| 208 abort(); | 219 abort(); |
| 209 } | 220 } |
| 210 | 221 |
| 211 | 222 |
| 212 void OS::Exit(int code) { | 223 void OS::Exit(int code) { |
| 213 exit(code); | 224 exit(code); |
| 214 } | 225 } |
| 215 | 226 |
| 216 } // namespace dart | 227 } // namespace dart |
| OLD | NEW |