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

Side by Side Diff: runtime/vm/os_win.cc

Issue 10037018: Fix OS::VSNPrint to make it behave similar to linux and macos versions. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 int OS::VSNPrint(char* str, size_t size, const char* format, va_list args) { 163 int OS::VSNPrint(char* str, size_t size, const char* format, va_list args) {
164 if (str == NULL || size == 0) {
165 return _vscprintf(format, args);
166 }
164 int written =_vsnprintf(str, size, format, args); 167 int written =_vsnprintf(str, size, format, args);
168 if (written < 0) {
169 // _vsnprintf returns -1 if the number of characters to be written is
170 // larger than 'size', so we call _vscprintf which returns the number
171 // of characters that would have been written.
172 written = _vscprintf(format, args);
Ivan Posva 2012/04/11 07:34:39 You are reusing the args here which is a big NO-NO
siva 2012/04/11 23:12:51 Good point. I have uploaded a CL doing the va_copy
173 }
165 // Make sure to zero-terminate the string if the output was 174 // Make sure to zero-terminate the string if the output was
166 // truncated or if there was an error. 175 // truncated or if there was an error.
167 if (written < 0 || written >= size) { 176 if (written >= size) {
168 if (size > 0) { 177 str[size - 1] = '\0';
169 str[size - 1] = '\0';
170 }
171 } 178 }
172 return written; 179 return written;
173 } 180 }
174 181
175 182
176 void OS::PrintErr(const char* format, ...) { 183 void OS::PrintErr(const char* format, ...) {
177 va_list args; 184 va_list args;
178 va_start(args, format); 185 va_start(args, format);
179 VFPrint(stderr, format, args); 186 VFPrint(stderr, format, args);
180 va_end(args); 187 va_end(args);
(...skipping 19 matching lines...) Expand all
200 void OS::Abort() { 207 void OS::Abort() {
201 abort(); 208 abort();
202 } 209 }
203 210
204 211
205 void OS::Exit(int code) { 212 void OS::Exit(int code) {
206 exit(code); 213 exit(code);
207 } 214 }
208 215
209 } // namespace dart 216 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698