mirror of
https://github.com/reactos/reactos.git
synced 2025-07-27 21:22:24 +00:00
strncpy does add NUL bytes to fill dest buffer completely,
however lstrcpyn does not. svn path=/trunk/; revision=7893
This commit is contained in:
parent
18a0b41cb6
commit
88c6922a90
3 changed files with 42 additions and 4 deletions
|
@ -50,7 +50,25 @@ lstrcpynA(
|
||||||
int iMaxLength
|
int iMaxLength
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return strncpy(lpString1,lpString2,iMaxLength);
|
/* Can't use strncpy, because strncpy will fill unused bytes in
|
||||||
|
lpString1 with NUL bytes while lstrcpynA doesn't */
|
||||||
|
|
||||||
|
if (0 != iMaxLength)
|
||||||
|
{
|
||||||
|
char *d = lpString1;
|
||||||
|
const char *s = lpString2;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (0 == (*d++ = *s++))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while(0 != --iMaxLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
return lpString1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -134,7 +152,25 @@ lstrcpynW(
|
||||||
int iMaxLength
|
int iMaxLength
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return wcsncpy(lpString1,lpString2,iMaxLength);
|
/* Can't use wcsncpy, because wcsncpy will fill unused bytes in
|
||||||
|
lpString1 with NUL bytes while lstrcpynW doesn't */
|
||||||
|
|
||||||
|
if (0 != iMaxLength)
|
||||||
|
{
|
||||||
|
WCHAR *d = lpString1;
|
||||||
|
const WCHAR *s = lpString2;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (0 == (*d++ = *s++))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while(0 != --iMaxLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
return lpString1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: tcsncpy.h,v 1.2 2004/01/27 21:43:47 gvg Exp $
|
/* $Id: tcsncpy.h,v 1.3 2004/01/28 08:51:09 gvg Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "tchar.h"
|
#include "tchar.h"
|
||||||
|
@ -22,6 +22,7 @@ _tcsncpy:
|
||||||
_tstos
|
_tstos
|
||||||
test %_treg(a), %_treg(a)
|
test %_treg(a), %_treg(a)
|
||||||
jnz .L1
|
jnz .L1
|
||||||
|
rep _tstos
|
||||||
|
|
||||||
.L2:
|
.L2:
|
||||||
mov 0x0C(%esp), %eax
|
mov 0x0C(%esp), %eax
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: tcsncpy.h,v 1.2 2004/01/27 21:43:47 gvg Exp $
|
/* $Id: tcsncpy.h,v 1.3 2004/01/28 08:51:09 gvg Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
@ -15,6 +15,7 @@ _TCHAR * _tcsncpy(_TCHAR * dst, const _TCHAR * src, size_t n)
|
||||||
{
|
{
|
||||||
if((*d ++ = *s ++) == 0)
|
if((*d ++ = *s ++) == 0)
|
||||||
{
|
{
|
||||||
|
while (-- n != 0) *d ++ = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue