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

Unified Diff: src/platform-win32.cc

Issue 7308007: MinGW32: define STRUNCATE (Closed)
Patch Set: Do the right thing Created 9 years, 5 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
+ }
}
« 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