| 415 | } |
| 416 | |
| 417 | S32 dStrlcpy(char *dst, const char *src, dsize_t dstSize) |
| 418 | { |
| 419 | //TODO: Do other platforms support strlcpy in their libc |
| 420 | #ifdef TORQUE_OS_MAC |
| 421 | S32 len = strlcpy(dst, src, dstSize); |
| 422 | |
| 423 | AssertWarn(len < dstSize, "Buffer too small in call to dStrlcpy!"); |
| 424 | |
| 425 | return len; |
| 426 | #else //TORQUE_OS_MAC |
| 427 | S32 srcLen = dStrlen(src); |
| 428 | S32 copyLen = srcLen; |
| 429 | |
| 430 | //Check for buffer overflow and don't allow it. Warn on debug so we can fix it |
| 431 | AssertFatal(copyLen < dstSize, "Buffer too small in call to dStrlcpy!"); |
| 432 | if (srcLen + 1 > dstSize) |
| 433 | { |
| 434 | copyLen = dstSize - 1; |
| 435 | } |
| 436 | |
| 437 | //Copy src and null terminate |
| 438 | memcpy(dst, src, copyLen); |
| 439 | dst[copyLen] = 0; |
| 440 | |
| 441 | //Return the length of the string we would have generated |
| 442 | return srcLen; |
| 443 | #endif //TORQUE_OS_MAC |
| 444 | } |
| 445 | |
| 446 | //------------------------------------------------------------------------------ |
| 447 | // standard I/O functions |