Implement WelsStrcat based on WelsStrncpy

This is a more convenient behaviour (truncating on overflow and
always null terminating the buffer) compared to the MSVC
safe strcat_s which aborts the process if the string doesn't fit
into the target buffer.

Also mark the source buffer as const in the function prototype.
This commit is contained in:
Martin Storsjö 2014-01-28 12:21:34 +02:00
parent 9840f11784
commit fa93c88fa2
2 changed files with 6 additions and 1 deletions

View File

@ -234,6 +234,11 @@ int32_t WelsStrftime (str_t* pBuffer, int32_t iSize, const str_t* kpFormat, cons
#endif
str_t* WelsStrcat (str_t* pDest, int32_t iSizeInBytes, const str_t* kpSrc) {
int32_t iCurLen = strlen(pDest);
return WelsStrncpy(pDest + iCurLen, iSizeInBytes - iCurLen, kpSrc);
}
int32_t WelsFwrite (const void_t* kpBuffer, int32_t iSize, int32_t iCount, WelsFileHandle* pFp) {
return fwrite (kpBuffer, iSize, iCount, pFp);
}

View File

@ -77,7 +77,7 @@ typedef struct timeb SWelsTime;
int32_t WelsSnprintf (str_t* buffer, int32_t sizeOfBuffer, const str_t* format, ...);
str_t* WelsStrncpy (str_t* dest, int32_t sizeInBytes, const str_t* src);
str_t* WelsStrcat (str_t* dest, int32_t sizeInBytes, str_t* src);
str_t* WelsStrcat (str_t* dest, int32_t sizeInBytes, const str_t* src);
int32_t WelsVsnprintf (str_t* buffer, int32_t sizeOfBuffer, const str_t* format, va_list argptr);
WelsFileHandle* WelsFopen (const str_t* filename, const str_t* mode);