| 421 | |
| 422 | |
| 423 | void strlcpy(LPSTR aDst, LPCSTR aSrc, size_t aDstSize) // Non-inline because it benches slightly faster that way. |
| 424 | // Caller must ensure that aDstSize is greater than 0. |
| 425 | // Caller must ensure that the entire capacity of aDst is writable, EVEN WHEN it knows that aSrc is much shorter |
| 426 | // than the aDstSize. This is because the call to strncpy (which is used for its superior performance) zero-fills |
| 427 | // any unused portion of aDst. |
| 428 | // Description: |
| 429 | // Same as strncpy() but guarantees null-termination of aDst upon return. |
| 430 | // No more than aDstSize - 1 characters will be copied from aSrc into aDst |
| 431 | // (leaving room for the zero terminator, which is always inserted). |
| 432 | // This function is defined in some Unices but is not standard. But unlike |
| 433 | // other versions, this one uses void for return value for reduced code size |
| 434 | // (since it's called in so many places). |
| 435 | { |
| 436 | // Disabled for performance and reduced code size: |
| 437 | //if (!aDst || !aSrc || !aDstSize) return aDstSize; // aDstSize must not be zero due to the below method. |
| 438 | // It might be worthwhile to have a custom char-copying-loop here someday so that number of characters |
| 439 | // actually copied (not including the zero terminator) can be returned to callers who want it. |
| 440 | --aDstSize; // Convert from size to length (caller has ensured that aDstSize > 0). |
| 441 | strncpy(aDst, aSrc, aDstSize); // NOTE: In spite of its zero-filling, strncpy() benchmarks considerably faster than a custom loop, probably because it uses 32-bit memory operations vs. 8-bit. |
| 442 | aDst[aDstSize] = '\0'; |
| 443 | } |
| 444 | |
| 445 | |
| 446 |
nothing calls this directly
no outgoing calls
no test coverage detected