summaryrefslogtreecommitdiffhomepage
path: root/src/string
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2018-06-14 07:51:51 +0000
committermidipix <writeonce@midipix.org>2018-06-14 07:49:38 -0400
commitaac1ecb7acc5196664ef65a2467cbe45c097841c (patch)
treee1fefcedf6fc20a83251a30ab64da44d8377857f /src/string
parentf7c707fbe9b789803030fe278e3177cd79c0d3cf (diff)
downloadntapi-aac1ecb7acc5196664ef65a2467cbe45c097841c.tar.bz2
ntapi-aac1ecb7acc5196664ef65a2467cbe45c097841c.tar.xz
string helper api's: added ntapi_tt_uintptr_to_dec{_null}_utf{8|16}().
Diffstat (limited to 'src/string')
-rw-r--r--src/string/ntapi_tt_uintptr_to_dec.c148
1 files changed, 148 insertions, 0 deletions
diff --git a/src/string/ntapi_tt_uintptr_to_dec.c b/src/string/ntapi_tt_uintptr_to_dec.c
new file mode 100644
index 0000000..c496247
--- /dev/null
+++ b/src/string/ntapi_tt_uintptr_to_dec.c
@@ -0,0 +1,148 @@
+/********************************************************/
+/* ntapi: Native API core library */
+/* Copyright (C) 2013--2018 Z. Gilboa */
+/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */
+/********************************************************/
+
+#include <psxtypes/psxtypes.h>
+#include <ntapi/nt_status.h>
+
+static void __tt_uintptr_to_mirrored_dec_utf8(
+ uintptr_t key,
+ unsigned char * buf,
+ ssize_t * arrlen)
+{
+ unsigned i;
+
+ buf[0] = '0' + (key % 10);
+ key /= 10;
+
+ for (i=1; key; i++) {
+ buf[i] = '0' + (key % 10);
+ key /= 10;
+ }
+
+ *arrlen = i;
+}
+
+static int32_t __tt_uintptr_to_dec_utf16(
+ uintptr_t key,
+ wchar16_t * wstrbuf,
+ size_t buflen,
+ ssize_t * arrlen)
+{
+ ssize_t i;
+ ssize_t slen;
+ unsigned char buf[24];
+
+ __tt_uintptr_to_mirrored_dec_utf8(
+ key,buf,arrlen);
+
+ if ((i = *arrlen) > (slen = buflen))
+ return NT_STATUS_BUFFER_TOO_SMALL;
+
+ for (--i; i>=0; i--)
+ *wstrbuf++ = buf[i];
+
+ return NT_STATUS_SUCCESS;
+}
+
+static int32_t __tt_uintptr_to_dec_utf8(
+ uintptr_t key,
+ unsigned char * strbuf,
+ size_t buflen,
+ ssize_t * arrlen)
+{
+ ssize_t i;
+ ssize_t slen;
+ unsigned char buf[24];
+
+ __tt_uintptr_to_mirrored_dec_utf8(
+ key,buf,arrlen);
+
+ if ((i = *arrlen) > (slen = buflen))
+ return NT_STATUS_BUFFER_TOO_SMALL;
+
+ for (--i; i>=0; i--)
+ *strbuf++ = buf[i];
+
+ return NT_STATUS_SUCCESS;
+}
+
+int32_t __stdcall __ntapi_tt_uintptr_to_dec_utf16(
+ __in uintptr_t key,
+ __out wchar16_t * wstrbuf,
+ __in size_t buflen,
+ __out ssize_t * length)
+{
+ int32_t status;
+ ssize_t arrlen;
+
+ buflen /= sizeof(wchar16_t);
+
+ status = __tt_uintptr_to_dec_utf16(
+ key,wstrbuf,
+ buflen,&arrlen);
+
+ *length = arrlen * sizeof(wchar16_t);
+
+ return status;
+}
+
+int32_t __stdcall __ntapi_tt_uintptr_to_dec_utf8(
+ __in uintptr_t key,
+ __out unsigned char * strbuf,
+ __in size_t buflen,
+ __out ssize_t * length)
+{
+ return __tt_uintptr_to_dec_utf8(
+ key,strbuf,
+ buflen,length);
+}
+
+
+int32_t __stdcall __ntapi_tt_uintptr_to_dec_null_utf16(
+ __in uintptr_t key,
+ __out wchar16_t * wstrbuf,
+ __in size_t buflen,
+ __out ssize_t * length)
+{
+ int32_t status;
+ ssize_t arrlen;
+
+ buflen -= sizeof(wchar16_t);
+ buflen /= sizeof(wchar16_t);
+
+ status = __tt_uintptr_to_dec_utf16(
+ key,wstrbuf,
+ buflen,&arrlen);
+
+ if (status == NT_STATUS_SUCCESS)
+ wstrbuf[arrlen] = 0;
+
+ *length = ++arrlen * sizeof(wchar16_t);
+
+ return status;
+}
+
+
+int32_t __stdcall __ntapi_tt_uintptr_to_dec_null_utf8(
+ __in uintptr_t key,
+ __out unsigned char * strbuf,
+ __in size_t buflen,
+ __out ssize_t * length)
+{
+ int32_t status;
+ ssize_t arrlen;
+
+ status = __tt_uintptr_to_dec_utf8(
+ key,strbuf,
+ --buflen,&arrlen);
+
+ if (status == NT_STATUS_SUCCESS)
+ strbuf[arrlen] = 0;
+
+ *length = ++arrlen;
+
+ return status;
+}