Blame src/string/ntapi_tt_dec_utf16_to_uintptr.c

23d954
/********************************************************/
23d954
/*  ntapi: Native API core library                      */
59d585
/*  Copyright (C) 2013--2021  Z. Gilboa                 */
23d954
/*  Released under GPLv2 and GPLv3; see COPYING.NTAPI.  */
23d954
/********************************************************/
23d954
23d954
#include <psxtypes/psxtypes.h>
23d954
#include <ntapi/nt_status.h>
766a63
#include "ntapi_impl.h"
23d954
23d954
static int32_t __tt_dec_utf16_to_uint64(
23d954
	__in	const wchar16_t *	wch_arg,
23d954
	__in	const wchar16_t *	wch_cap,
23d954
	__out	uint64_t *		key)
23d954
{
23d954
	int32_t			status;
23d954
	uint64_t		lkey;
23d954
	uint64_t		hkey;
23d954
	const wchar16_t *	wch;
23d954
23d954
	if (wch_cap <= wch_arg)
23d954
		return NT_STATUS_INVALID_PARAMETER;
23d954
23d954
	else if (wch_cap - wch_arg > 20)
23d954
		return NT_STATUS_INVALID_PARAMETER;
23d954
23d954
	lkey = 0;
23d954
	hkey = 0;
23d954
23d954
	if (wch_cap - wch_arg == 20) {
23d954
		if ((status = __tt_dec_utf16_to_uint64(
23d954
				&wch_arg[6],wch_cap,
23d954
				&hkey)))
23d954
			return status;
23d954
23d954
		if (hkey > 18446744073709)
23d954
			return NT_STATUS_INTEGER_OVERFLOW;
23d954
23d954
		hkey   *= 1000000;
23d954
		wch_cap = &wch_arg[6];
23d954
	}
23d954
23d954
	for (wch=wch_arg; wch
23d954
		if ((*wch < '0') || (*wch > '9'))
23d954
			return NT_STATUS_INVALID_PARAMETER;
23d954
23d954
		lkey *= 10;
23d954
		lkey += *wch - '0';
23d954
	}
23d954
23d954
	*key = lkey + hkey;
23d954
23d954
	return NT_STATUS_SUCCESS;
23d954
}
23d954
23d954
int32_t __stdcall __ntapi_tt_dec_utf16_to_uint16(
23d954
	__in	const wchar16_t *	wch_arg,
23d954
	__in	const wchar16_t *	wch_cap,
23d954
	__out	uint16_t *		key)
23d954
{
23d954
	int32_t		status;
23d954
	uint64_t	skey;
23d954
	uint16_t	rkey;
23d954
23d954
	if ((status = __tt_dec_utf16_to_uint64(wch_arg,wch_cap,&skey)))
23d954
		return status;
23d954
23d954
	if ((rkey = skey) < skey)
23d954
		return NT_STATUS_INTEGER_OVERFLOW;
23d954
23d954
	*key = rkey;
23d954
23d954
	return NT_STATUS_SUCCESS;
23d954
}
23d954
23d954
int32_t __stdcall __ntapi_tt_dec_utf16_to_uint32(
23d954
	__in	const wchar16_t *	wch_arg,
23d954
	__in	const wchar16_t *	wch_cap,
23d954
	__out	uint32_t *		key)
23d954
{
23d954
	int32_t		status;
23d954
	uint64_t	skey;
23d954
	uint32_t	rkey;
23d954
23d954
	if ((status = __tt_dec_utf16_to_uint64(wch_arg,wch_cap,&skey)))
23d954
		return status;
23d954
23d954
	if ((rkey = skey) < skey)
23d954
		return NT_STATUS_INTEGER_OVERFLOW;
23d954
23d954
	*key = rkey;
23d954
23d954
	return NT_STATUS_SUCCESS;
23d954
}
23d954
23d954
23d954
23d954
int32_t __stdcall __ntapi_tt_dec_utf16_to_uint64(
23d954
	__in	const wchar16_t *	wch_arg,
23d954
	__in	const wchar16_t *	wch_cap,
23d954
	__out	uint64_t *		key)
23d954
{
23d954
	return __tt_dec_utf16_to_uint64(
23d954
		wch_arg,wch_cap,key);
23d954
}
23d954
23d954
#ifdef __NT32
23d954
int32_t __stdcall __ntapi_tt_dec_utf16_to_uintptr(
23d954
	__in	const wchar16_t *	wch_arg,
23d954
	__in	const wchar16_t *	wch_cap,
23d954
	__out	uintptr_t *		key)
23d954
{
1cfd22
	return __ntapi_tt_dec_utf16_to_uint32(
23d954
		wch_arg,wch_cap,key);
23d954
}
23d954
#endif
23d954
23d954
#ifdef __NT64
23d954
int32_t __stdcall __ntapi_tt_dec_utf16_to_uintptr(
23d954
	__in	const wchar16_t *	wch_arg,
23d954
	__in	const wchar16_t *	wch_cap,
23d954
	__out	uintptr_t *		key)
23d954
{
23d954
	return __tt_dec_utf16_to_uint64(
23d954
		wch_arg,wch_cap,key);
23d954
}
23d954
#endif