There\'re certain cases when I really need strncpy()
funcitonalty - for example I have a function in a predefined interface that is passed an address of the buf
You might use memcpy_s instead.
HRESULT someFunction( char* buffer, size_t length )
{
const char* toCopy = ...
size_t actualLength = strlen( toCopy );
if( actualLength > length ) {
return E_UNEXPECTED; // doesn't fit, can't do anything reasonable
}
else if ( actualLength < length ) {
actualLength++; // copy null terminator too
}
memcpy_s( buffer, length, toCopy, actualLength );
return S_OK;
}