Rewrite _sys_strncpy

This commit is contained in:
Nekotekina 2017-09-17 16:49:33 +03:00
parent 871ccfd32c
commit 22ff8abd7d

View File

@ -297,18 +297,29 @@ vm::ptr<char> _sys_strcpy(vm::ptr<char> dst, vm::cptr<char> src)
}
}
vm::ptr<char> _sys_strncpy(vm::ptr<char> dest, vm::cptr<char> source, u32 len)
vm::ptr<char> _sys_strncpy(vm::ptr<char> dst, vm::cptr<char> src, s32 len)
{
sysPrxForUser.trace("_sys_strncpy(dest=*0x%x, source=%s, len=%d)", dest, source, len);
sysPrxForUser.trace("_sys_strncpy(dst=*0x%x %s, src=%s, len=%d)", dst, dst, src, len);
if (!dest || !source)
if (!dst || !src)
{
return vm::null;
}
verify(HERE), std::strncpy(dest.get_ptr(), source.get_ptr(), len) == dest.get_ptr();
for (s32 i = 0; i < len; i++)
{
if (!(dst[i] = src[i]))
{
for (++i; i < len; i++)
{
dst[i] = '\0';
}
return dest;
return dst;
}
}
return dst;
}
s32 _sys_strncasecmp(vm::cptr<char> str1, vm::cptr<char> str2, u32 n)