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

Unified Diff: src/platform-win32.cc

Issue 1940: Replaced calls to functions that msvc consider deprecated. Used... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 12 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/platform-linux.cc ('k') | src/prettyprinter.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/platform-win32.cc
===================================================================
--- src/platform-win32.cc (revision 280)
+++ src/platform-win32.cc (working copy)
@@ -156,14 +156,14 @@
// Case-insensitive string comparisons. Use stricmp() on Win32. Usually defined
// in strings.h.
int strcasecmp(const char* s1, const char* s2) {
- return stricmp(s1, s2);
+ return _stricmp(s1, s2);
}
// Case-insensitive bounded string comparisons. Use stricmp() on Win32. Usually
// defined in strings.h.
int strncasecmp(const char* s1, const char* s2, int n) {
- return strnicmp(s1, s2, n);
+ return _strnicmp(s1, s2, n);
}
namespace v8 { namespace internal {
@@ -341,9 +341,13 @@
}
// Make standard and DST timezone names.
- _snprintf(std_tz_name_, kTzNameSize, "%S", tzinfo_.StandardName);
+ OS::SNPrintF(Vector<char>(std_tz_name_, kTzNameSize),
+ "%S",
+ tzinfo_.StandardName);
std_tz_name_[kTzNameSize - 1] = '\0';
- _snprintf(dst_tz_name_, kTzNameSize, "%S", tzinfo_.DaylightName);
+ OS::SNPrintF(Vector<char>(dst_tz_name_, kTzNameSize),
+ "%S",
+ tzinfo_.DaylightName);
dst_tz_name_[kTzNameSize - 1] = '\0';
// If OS returned empty string or resource id (like "@tzres.dll,-211")
@@ -351,12 +355,14 @@
// To properly resolve the resource identifier requires a library load,
// which is not possible in a sandbox.
if (std_tz_name_[0] == '\0' || std_tz_name_[0] == '@') {
- _snprintf(std_tz_name_, kTzNameSize - 1, "%s Standard Time",
- GuessTimezoneNameFromBias(tzinfo_.Bias));
+ OS::SNPrintF(Vector<char>(std_tz_name_, kTzNameSize - 1),
+ "%s Standard Time",
+ GuessTimezoneNameFromBias(tzinfo_.Bias));
}
if (dst_tz_name_[0] == '\0' || dst_tz_name_[0] == '@') {
- _snprintf(dst_tz_name_, kTzNameSize - 1, "%s Daylight Time",
- GuessTimezoneNameFromBias(tzinfo_.Bias));
+ OS::SNPrintF(Vector<char>(dst_tz_name_, kTzNameSize - 1),
+ "%s Daylight Time",
+ GuessTimezoneNameFromBias(tzinfo_.Bias));
}
// Timezone information initialized.
@@ -607,14 +613,23 @@
// It is important to use safe print here in order to avoid
// overflowing the buffer. We might truncate the output, but this
// does not crash.
- static const int kBufferSize = 4096;
- char buffer[kBufferSize];
- OS::VSNPrintF(buffer, kBufferSize, format, args);
- OutputDebugStringA(buffer);
+ EmbeddedVector<char, 4096> buffer;
+ OS::VSNPrintF(buffer, format, args);
+ OutputDebugStringA(buffer.start());
}
}
+FILE* OS::FOpen(const char* path, const char* mode) {
+ FILE* result;
+ if (fopen_s(&result, path, mode) == 0) {
+ return result;
+ } else {
+ return NULL;
+ }
+}
+
+
// Print (debug) message to console.
void OS::Print(const char* format, ...) {
va_list args;
@@ -643,24 +658,21 @@
}
-int OS::SNPrintF(char* str, size_t size, const char* format, ...) {
+int OS::SNPrintF(Vector<char> str, const char* format, ...) {
va_list args;
va_start(args, format);
- int result = VSNPrintF(str, size, format, args);
+ int result = VSNPrintF(str, format, args);
va_end(args);
return result;
}
-int OS::VSNPrintF(char* str, size_t size, const char* format, va_list args) {
- // Print formated output to string. The _vsnprintf function has been
- // deprecated in MSVC. We need to define _CRT_NONSTDC_NO_DEPRECATE
- // during compilation to use it anyway. Usually defined in stdio.h.
- int n = _vsnprintf(str, size, format, args);
+int OS::VSNPrintF(Vector<char> str, const char* format, va_list args) {
+ int n = _vsnprintf_s(str.start(), str.length(), str.length(), format, args);
// Make sure to zero-terminate the string if the output was
// truncated or if there was an error.
- if (n < 0 || static_cast<size_t>(n) >= size) {
- str[size - 1] = '\0';
+ if (n < 0 || n >= str.length()) {
+ str[str.length() - 1] = '\0';
return -1;
} else {
return n;
@@ -668,6 +680,23 @@
}
+void OS::StrNCpy(Vector<char> dest, const char* src, size_t n) {
+ int result = strncpy_s(dest.start(), dest.length(), src, n);
+ USE(result); ASSERT(result == 0);
+}
+
+
+void OS::WcsCpy(Vector<wchar_t> dest, const wchar_t* src) {
+ int result = wcscpy_s(dest.start(), dest.length(), src);
+ USE(result); ASSERT(result == 0);
+}
+
+
+char *OS::StrDup(const char* str) {
+ return _strdup(str);
+}
+
+
// We keep the lowest and highest addresses mapped as a quick way of
// determining that pointers are outside the heap (used mostly in assertions
// and verification). The estimate is conservative, ie, not all addresses in
@@ -1132,11 +1161,15 @@
// Format a text representation of the frame based on the information
// available.
if (ok) {
- SNPrintF(frames[frames_count].text, kStackWalkMaxTextLen, "%s %s:%d:%d",
+ SNPrintF(MutableCStrVector(frames[frames_count].text,
+ kStackWalkMaxTextLen),
+ "%s %s:%d:%d",
symbol->Name, Line.FileName, Line.LineNumber,
line_displacement);
} else {
- SNPrintF(frames[frames_count].text, kStackWalkMaxTextLen, "%s",
+ SNPrintF(MutableCStrVector(frames[frames_count].text,
+ kStackWalkMaxTextLen),
+ "%s",
symbol->Name);
}
// Make sure line termination is in place.
« no previous file with comments | « src/platform-linux.cc ('k') | src/prettyprinter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698