Last active
September 29, 2020 13:58
-
-
Save dougpuob/c2fe5b8862665273aa114d982830d0ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\atlmfc\include\atlutil.h | |
inline char * __cdecl _strncpy( | |
_Out_writes_z_(count) char * dest, | |
_In_reads_z_(count) const char * source, | |
_In_ size_t count) throw() | |
{ | |
ATLASSERT( dest != NULL ); | |
ATLASSERT( source != NULL ); | |
if(!dest || count==0) | |
{ | |
return NULL; | |
} | |
if(dest!=source) | |
{ | |
dest[0]='\0'; | |
} | |
if(!source && count>0) | |
{ | |
return NULL; | |
} | |
char *start = dest; | |
while (count && (*dest++ = *source++)) | |
{ | |
count--; | |
} | |
return(start); | |
} | |
inline bool _SafeStringCopy( | |
_Out_writes_z_(nLen) char *szDest, | |
_In_reads_z_(nLen) const char *szSrc, | |
_In_ size_t nLen) throw() | |
{ | |
ATLASSERT( szDest != NULL ); | |
ATLASSERT( szSrc != NULL ); | |
// initialize for check below | |
szDest[nLen-1] = '\0'; | |
_strncpy(szDest, szSrc, nLen); | |
if ('\0' != szDest[nLen-1]) | |
{ | |
// string was too large | |
szDest[nLen-1] = '\0'; | |
return false; | |
} | |
return true; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment