| 385 | //------------------------------------------------------------------------------ |
| 386 | |
| 387 | S32 dStrlcat(char *dst, const char *src, dsize_t dstSize) |
| 388 | { |
| 389 | //TODO: Do other platforms support strlcat in their libc |
| 390 | #ifdef TORQUE_OS_MAC |
| 391 | S32 len = strlcat(dst, src, dstSize); |
| 392 | |
| 393 | AssertWarn(len < dstSize, "Buffer too small in call to dStrlcat!"); |
| 394 | |
| 395 | return len; |
| 396 | #else //TORQUE_OS_MAC |
| 397 | S32 dstLen = dStrlen(dst); |
| 398 | S32 srcLen = dStrlen(src); |
| 399 | S32 copyLen = srcLen; |
| 400 | |
| 401 | //Check for buffer overflow and don't allow it. Warn on debug so we can fix it |
| 402 | AssertWarn(dstLen + copyLen < dstSize, "Buffer too small in call to dStrlcat!"); |
| 403 | if (dstLen + copyLen + 1 > dstSize) |
| 404 | { |
| 405 | copyLen = dstSize - dstLen - 1; |
| 406 | } |
| 407 | |
| 408 | //Copy src after dst and null terminate |
| 409 | memcpy(dst + dstLen, src, copyLen); |
| 410 | dst[dstLen + copyLen] = 0; |
| 411 | |
| 412 | //Return the length of the string we would have generated |
| 413 | return dstLen + srcLen; |
| 414 | #endif //TORQUE_OS_MAC |
| 415 | } |
| 416 | |
| 417 | S32 dStrlcpy(char *dst, const char *src, dsize_t dstSize) |
| 418 | { |