mirror of
https://github.com/reactos/reactos.git
synced 2025-04-04 20:50:41 +00:00
[CRT] Add a number of functions from wine
This adds _aligned_msize, _recalloc, wmemmove_s, memcpy_s, wmemcpy_s
This commit is contained in:
parent
d0a52a6d71
commit
c36ea58f32
1 changed files with 119 additions and 0 deletions
|
@ -26,6 +26,7 @@
|
|||
|
||||
#define MSVCRT_size_t size_t
|
||||
#define MSVCRT_intptr_t intptr_t
|
||||
#define MSVCRT_wchar_t wchar_t
|
||||
#define MSVCRT__HEAPBADNODE _HEAPBADNODE
|
||||
#define MSVCRT__HEAPOK _HEAPOK
|
||||
#define MSVCRT__HEAPEND _HEAPEND
|
||||
|
@ -35,6 +36,7 @@
|
|||
#define MSVCRT_EINVAL EINVAL
|
||||
#define MSVCRT_ENOSYS ENOSYS
|
||||
#define MSVCRT_ENOMEM ENOMEM
|
||||
#define MSVCRT_ERANGE ERANGE
|
||||
#define MSVCRT__TRUNCATE _TRUNCATE
|
||||
#define MSVCRT__heapinfo _heapinfo
|
||||
#define MSVCRT__errno _errno
|
||||
|
@ -42,6 +44,7 @@
|
|||
#define MSVCRT_malloc malloc
|
||||
#define MSVCRT_realloc realloc
|
||||
#define MSVCRT_free free
|
||||
#define MSVCRT_memcpy_s memcpy_s
|
||||
#define MSVCRT_memmove_s memmove_s
|
||||
#define MSVCRT_strncpy_s strncpy_s
|
||||
#define msvcrt_set_errno _dosmaperr
|
||||
|
@ -394,6 +397,22 @@ MSVCRT_size_t CDECL _msize(void* mem)
|
|||
return size;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* _aligned_msize (MSVCR100.@)
|
||||
*/
|
||||
size_t CDECL _aligned_msize(void *p, MSVCRT_size_t alignment, MSVCRT_size_t offset)
|
||||
{
|
||||
void **alloc_ptr;
|
||||
|
||||
if(!MSVCRT_CHECK_PMT(p)) return -1;
|
||||
|
||||
if(alignment < sizeof(void*))
|
||||
alignment = sizeof(void*);
|
||||
|
||||
alloc_ptr = SAVED_PTR(p);
|
||||
return _msize(*alloc_ptr)-alignment-sizeof(void*);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* calloc (MSVCRT.@)
|
||||
*/
|
||||
|
@ -432,6 +451,31 @@ void* CDECL MSVCRT_realloc(void* ptr, MSVCRT_size_t size)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* _recalloc (MSVCR100.@)
|
||||
*/
|
||||
void* CDECL _recalloc(void *mem, MSVCRT_size_t num, MSVCRT_size_t size)
|
||||
{
|
||||
MSVCRT_size_t old_size;
|
||||
void *ret;
|
||||
|
||||
if(!mem)
|
||||
return MSVCRT_calloc(num, size);
|
||||
|
||||
size = num*size;
|
||||
old_size = _msize(mem);
|
||||
|
||||
ret = MSVCRT_realloc(mem, size);
|
||||
if(!ret) {
|
||||
*MSVCRT__errno() = MSVCRT_ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(size>old_size)
|
||||
memset((BYTE*)ret+old_size, 0, size-old_size);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* __p__amblksiz (MSVCRT.@)
|
||||
*/
|
||||
|
@ -690,6 +734,81 @@ int CDECL MSVCRT_memmove_s(void *dest, MSVCRT_size_t numberOfElements, const voi
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* wmemmove_s (MSVCR100.@)
|
||||
*/
|
||||
int CDECL wmemmove_s(MSVCRT_wchar_t *dest, MSVCRT_size_t numberOfElements,
|
||||
const MSVCRT_wchar_t *src, MSVCRT_size_t count)
|
||||
{
|
||||
TRACE("(%p %lu %p %lu)\n", dest, numberOfElements, src, count);
|
||||
|
||||
if (!count)
|
||||
return 0;
|
||||
|
||||
/* Native does not seem to conform to 6.7.1.2.3 in
|
||||
* http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1225.pdf
|
||||
* in that it does not zero the output buffer on constraint violation.
|
||||
*/
|
||||
if (!MSVCRT_CHECK_PMT(dest != NULL)) return MSVCRT_EINVAL;
|
||||
if (!MSVCRT_CHECK_PMT(src != NULL)) return MSVCRT_EINVAL;
|
||||
if (!MSVCRT_CHECK_PMT_ERR(count <= numberOfElements, MSVCRT_ERANGE)) return MSVCRT_ERANGE;
|
||||
|
||||
memmove(dest, src, sizeof(MSVCRT_wchar_t)*count);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* memcpy_s (MSVCRT.@)
|
||||
*/
|
||||
int CDECL MSVCRT_memcpy_s(void *dest, MSVCRT_size_t numberOfElements, const void *src, MSVCRT_size_t count)
|
||||
{
|
||||
TRACE("(%p %lu %p %lu)\n", dest, numberOfElements, src, count);
|
||||
|
||||
if(!count)
|
||||
return 0;
|
||||
|
||||
if (!MSVCRT_CHECK_PMT(dest != NULL)) return MSVCRT_EINVAL;
|
||||
if (!MSVCRT_CHECK_PMT(src != NULL))
|
||||
{
|
||||
memset(dest, 0, numberOfElements);
|
||||
return MSVCRT_EINVAL;
|
||||
}
|
||||
if (!MSVCRT_CHECK_PMT_ERR( count <= numberOfElements, MSVCRT_ERANGE ))
|
||||
{
|
||||
memset(dest, 0, numberOfElements);
|
||||
return MSVCRT_ERANGE;
|
||||
}
|
||||
|
||||
memcpy(dest, src, count);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* wmemcpy_s (MSVCR100.@)
|
||||
*/
|
||||
int CDECL wmemcpy_s(MSVCRT_wchar_t *dest, MSVCRT_size_t numberOfElements,
|
||||
const MSVCRT_wchar_t *src, MSVCRT_size_t count)
|
||||
{
|
||||
TRACE("(%p %lu %p %lu)\n", dest, numberOfElements, src, count);
|
||||
|
||||
if (!count)
|
||||
return 0;
|
||||
|
||||
if (!MSVCRT_CHECK_PMT(dest != NULL)) return MSVCRT_EINVAL;
|
||||
|
||||
if (!MSVCRT_CHECK_PMT(src != NULL)) {
|
||||
memset(dest, 0, numberOfElements*sizeof(MSVCRT_wchar_t));
|
||||
return MSVCRT_EINVAL;
|
||||
}
|
||||
if (!MSVCRT_CHECK_PMT_ERR(count <= numberOfElements, MSVCRT_ERANGE)) {
|
||||
memset(dest, 0, numberOfElements*sizeof(MSVCRT_wchar_t));
|
||||
return MSVCRT_ERANGE;
|
||||
}
|
||||
|
||||
memcpy(dest, src, sizeof(MSVCRT_wchar_t)*count);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* strncpy_s (MSVCRT.@)
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue