MinGW32: define STRUNCATE and change strncpy_s implementation to follow specification.
This fixes the debug build for MinGW32 Patch by Bert Belder. Review URL: http://codereview.chromium.org/7308007 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8552 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
aed876cb21
commit
f465eeff69
@ -143,16 +143,39 @@ 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);
|
||||
int strncpy_s(char* dest, size_t dest_size, const char* source, size_t count) {
|
||||
CHECK(source != NULL);
|
||||
CHECK(dest != NULL);
|
||||
CHECK_GT(dest_size, 0);
|
||||
|
||||
if (count == _TRUNCATE) {
|
||||
while (dest_size > 0 && *source != 0) {
|
||||
*(dest++) = *(source++);
|
||||
--dest_size;
|
||||
}
|
||||
if (dest_size == 0) {
|
||||
*(dest - 1) = 0;
|
||||
return STRUNCATE;
|
||||
}
|
||||
} else {
|
||||
while (dest_size > 0 && count > 0 && *source != 0) {
|
||||
*(dest++) = *(source++);
|
||||
--dest_size;
|
||||
--count;
|
||||
}
|
||||
}
|
||||
CHECK_GT(dest_size, 0);
|
||||
*dest = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user