Index: src/platform-win32.cc |
diff --git a/src/platform-win32.cc b/src/platform-win32.cc |
index b7eed47cba86c8d5490b479e2f0934e4fde8ea26..9b093e08930b2db9ffa27d2cef9fe1a1b1b2287f 100644 |
--- a/src/platform-win32.cc |
+++ b/src/platform-win32.cc |
@@ -143,17 +143,43 @@ int fopen_s(FILE** pFile, const char* filename, const char* mode) { |
} |
+#define _TRUNCATE 0 |
+#define STRUNCATE 80 |
+ |
int _vsnprintf_s(char* buffer, size_t sizeOfBuffer, size_t count, |
const char* format, va_list argptr) { |
+ ASSERT(count == _TRUNCATE); |
return _vsnprintf(buffer, sizeOfBuffer, format, argptr); |
} |
-#define _TRUNCATE 0 |
-int strncpy_s(char* strDest, size_t numberOfElements, |
- const char* strSource, size_t count) { |
- strncpy(strDest, strSource, count); |
- return 0; |
+int strncpy_s(char* dest, size_t dest_size, const char* source, size_t count) { |
+ CHECK(source != NULL); |
+ CHECK(dest != NULL); |
+ CHECK(dest_size > 0); |
+ |
+ if (count == _TRUNCATE) { |
+ while (dest_size && *source != 0) { |
Vyacheslav Egorov (Chromium)
2011/07/06 12:10:33
Google Style Guide disallows implicit int to boole
|
+ *(dest++) = *(source++); |
+ --dest_size; |
+ } |
+ if (dest_size == 0) { |
+ *(dest - 1) = 0; |
+ return STRUNCATE; |
+ } |
+ *dest = 0; |
+ return 0; |
+ |
+ } else { |
+ while (dest_size && count && *source != 0) { |
Vyacheslav Egorov (Chromium)
2011/07/06 12:10:33
Ditto.
|
+ *(dest++) = *(source++); |
+ --dest_size; |
+ --count; |
+ } |
+ CHECK(dest_size > 0); |
+ *dest = 0; |
+ return 0; |
+ } |
} |