[SDK] Minor improvements to CRT, RTL, and headers
Signed-off-by: Quinn Stephens <quinn@osmora.org>
This commit is contained in:
parent
e81100b2e5
commit
e3f81a4c08
@ -5,7 +5,7 @@ Provided under the BSD 3-Clause license.
|
||||
|
||||
Module Name:
|
||||
|
||||
printf.c
|
||||
wprintf.c
|
||||
|
||||
Abstract:
|
||||
|
||||
|
@ -64,21 +64,17 @@ memmove (
|
||||
|
||||
/* Check for overlap */
|
||||
if (src > dest || ((char *)src + count) < (char *)dest) {
|
||||
/* Low-to-high copy, like memcpy() */
|
||||
while (count--) {
|
||||
*(char *)dest = *(char *)src;
|
||||
dest = (char *)dest + 1;
|
||||
src = (char *)src + 1;
|
||||
}
|
||||
} else {
|
||||
/* High-to-low copy */
|
||||
dest = (char *)dest + count - 1;
|
||||
src = (char *)src + count - 1;
|
||||
while (count--) {
|
||||
*(char *)dest = *(char *)src;
|
||||
dest = (char *)dest - 1;
|
||||
src = (char *)src - 1;
|
||||
}
|
||||
/* Low-to-high copy, use memcpy() */
|
||||
return memcpy(dest, src, count);
|
||||
}
|
||||
|
||||
/* High-to-low copy */
|
||||
dest = (char *)dest + count - 1;
|
||||
src = (char *)src + count - 1;
|
||||
while (count--) {
|
||||
*(char *)dest = *(char *)src;
|
||||
dest = (char *)dest - 1;
|
||||
src = (char *)src - 1;
|
||||
}
|
||||
|
||||
return ptr;
|
||||
|
@ -24,9 +24,11 @@ strlen (
|
||||
const char *ptr;
|
||||
|
||||
ptr = str;
|
||||
while (*ptr++);
|
||||
while (*ptr) {
|
||||
ptr++;
|
||||
}
|
||||
|
||||
return ptr - str - sizeof(char);
|
||||
return ptr - str;
|
||||
}
|
||||
|
||||
size_t
|
||||
@ -36,12 +38,14 @@ strnlen (
|
||||
)
|
||||
|
||||
{
|
||||
size_t len;
|
||||
const char *ptr;
|
||||
|
||||
len = 0;
|
||||
while (len < maxlen && str[len++]);
|
||||
ptr = str;
|
||||
while (maxlen-- && *ptr) {
|
||||
ptr++;
|
||||
}
|
||||
|
||||
return len - sizeof(char);
|
||||
return ptr - str;
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -26,8 +26,7 @@ wmemset (
|
||||
wchar_t *ptr = dest;
|
||||
|
||||
while (count--) {
|
||||
*(wchar_t *)dest = c;
|
||||
dest = (wchar_t *)dest + 1;
|
||||
*dest++ = c;
|
||||
}
|
||||
|
||||
return ptr;
|
||||
@ -44,9 +43,7 @@ wmemcpy (
|
||||
wchar_t *ptr = dest;
|
||||
|
||||
while (count--) {
|
||||
*(wchar_t *)dest = *(wchar_t *)src;
|
||||
dest = (wchar_t *)dest + 1;
|
||||
src = (wchar_t *)src + 1;
|
||||
*dest++ = *src++;
|
||||
}
|
||||
|
||||
return ptr;
|
||||
@ -64,21 +61,17 @@ wmemmove (
|
||||
|
||||
/* Check for overlap */
|
||||
if (src > dest || ((wchar_t *)src + count) < (wchar_t *)dest) {
|
||||
/* Low-to-high copy, like memcpy() */
|
||||
while (count--) {
|
||||
*(wchar_t *)dest = *(wchar_t *)src;
|
||||
dest = (wchar_t *)dest + 1;
|
||||
src = (wchar_t *)src + 1;
|
||||
}
|
||||
} else {
|
||||
/* High-to-low copy */
|
||||
dest = (wchar_t *)dest + count - 1;
|
||||
src = (wchar_t *)src + count - 1;
|
||||
while (count--) {
|
||||
*(wchar_t *)dest = *(wchar_t *)src;
|
||||
dest = (wchar_t *)dest - 1;
|
||||
src = (wchar_t *)src - 1;
|
||||
}
|
||||
/* Low-to-high copy, use wmemcpy() */
|
||||
return wmemcpy(dest, src, count);
|
||||
}
|
||||
|
||||
/* High-to-low copy */
|
||||
dest = (wchar_t *)dest + count - 1;
|
||||
src = (wchar_t *)src + count - 1;
|
||||
while (count--) {
|
||||
*(wchar_t *)dest = *(wchar_t *)src;
|
||||
dest = (wchar_t *)dest - 1;
|
||||
src = (wchar_t *)src - 1;
|
||||
}
|
||||
|
||||
return ptr;
|
||||
|
@ -24,7 +24,9 @@ wcslen (
|
||||
const wchar_t *ptr;
|
||||
|
||||
ptr = str;
|
||||
while (*ptr++);
|
||||
while (*ptr) {
|
||||
ptr++;
|
||||
}
|
||||
|
||||
return ptr - str;
|
||||
}
|
||||
@ -36,15 +38,14 @@ wcsnlen (
|
||||
)
|
||||
|
||||
{
|
||||
size_t len;
|
||||
const wchar_t *ptr;
|
||||
|
||||
len = 0;
|
||||
while (len < maxlen && *str) {
|
||||
len++;
|
||||
str++;
|
||||
ptr = str;
|
||||
while (maxlen-- && *ptr) {
|
||||
ptr++;
|
||||
}
|
||||
|
||||
return len;
|
||||
return ptr - str;
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -53,6 +53,8 @@ typedef long int ptrdiff_t;
|
||||
typedef unsigned short wchar_t;
|
||||
#endif
|
||||
|
||||
#define offsetof(type, member) __builtin_offsetof(type, member)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -18,11 +18,15 @@ Abstract:
|
||||
#ifndef _STRING_H
|
||||
#define _STRING_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
void *memset(void *dest, int c, size_t count);
|
||||
void *memcpy(void *dest, const void *src, size_t count);
|
||||
void *memmove(void *dest, const void *src, size_t count);
|
||||
|
||||
size_t strlen(const char *str);
|
||||
size_t strnlen(const char *str, size_t maxlen);
|
||||
@ -31,10 +35,6 @@ int strncmp(const char* s1, const char* s2, size_t n);
|
||||
char *strchr(const char *s, int c);
|
||||
char *strstr(const char *haystack, const char *needle);
|
||||
|
||||
void *memset(void *dest, int c, size_t count);
|
||||
void *memcpy(void *dest, const void *src, size_t count);
|
||||
void *memmove(void *dest, const void *src, size_t count);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -18,12 +18,16 @@ Abstract:
|
||||
#ifndef _WCHAR_H
|
||||
#define _WCHAR_H
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
wchar_t *wmemset(wchar_t *dest, wchar_t c, size_t count);
|
||||
wchar_t *wmemcpy(wchar_t *dest, const wchar_t *src, size_t count);
|
||||
wchar_t *wmemmove(wchar_t *dest, const wchar_t *src, size_t count);
|
||||
|
||||
size_t wcslen(const wchar_t *str);
|
||||
size_t wcsnlen(const wchar_t *str, size_t maxlen);
|
||||
@ -34,10 +38,6 @@ wchar_t *wcsstr(const wchar_t *haystack, const wchar_t *needle);
|
||||
wchar_t *wcscpy_s(wchar_t *dest, size_t maxlen, const wchar_t *src);
|
||||
wchar_t *wcscat_s(wchar_t *dest, size_t maxlen, const wchar_t *src);
|
||||
|
||||
wchar_t *wmemset(wchar_t *dest, wchar_t c, size_t count);
|
||||
wchar_t *wmemcpy(wchar_t *dest, const wchar_t *src, size_t count);
|
||||
wchar_t *wmemmove(wchar_t *dest, const wchar_t *src, size_t count);
|
||||
|
||||
int vswprintf(wchar_t *wcs, size_t maxlen, const wchar_t *format, va_list args);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -111,44 +111,19 @@ typedef long long LONGLONG;
|
||||
typedef unsigned long long ULONGLONG;
|
||||
#endif
|
||||
|
||||
typedef LONGLONG *PLONGLONG;
|
||||
typedef ULONGLONG *PULONGLONG;
|
||||
|
||||
#define MAXLONGLONG 0x7fffffffffffffff
|
||||
#define MAXULONGLONG 0xffffffffffffffff
|
||||
|
||||
#define LODWORD(x) ((ULONG)(x))
|
||||
#define HIDWORD(x) ((ULONG)((x) >> 32))
|
||||
|
||||
#define LOWORD(x) ((USHORT)(x))
|
||||
#define HIWORD(x) ((USHORT)((x) >> 16))
|
||||
|
||||
#define LOBYTE(x) ((UCHAR)(x))
|
||||
#define HIBYTE(x) ((UCHAR)((x) >> 8))
|
||||
|
||||
//
|
||||
// Logical/boolean value types.
|
||||
//
|
||||
typedef ULONG LOGICAL;
|
||||
typedef ULONG *PLOGICAL;
|
||||
typedef int BOOL;
|
||||
typedef BOOL *PBOOL;
|
||||
typedef UCHAR BOOLEAN;
|
||||
typedef BOOLEAN *PBOOLEAN;
|
||||
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
//
|
||||
// Basic pointer types.
|
||||
//
|
||||
typedef VOID *PVOID;
|
||||
typedef CHAR *PCHAR;
|
||||
typedef SHORT *PSHORT;
|
||||
typedef UCHAR *PUCHAR;
|
||||
typedef USHORT *PUSHORT;
|
||||
typedef ULONG *PULONG;
|
||||
|
||||
//
|
||||
// Numeric pointer types.
|
||||
//
|
||||
@ -160,6 +135,29 @@ typedef LONG LONG_PTR;
|
||||
typedef ULONG ULONG_PTR;
|
||||
#endif
|
||||
|
||||
//
|
||||
// Basic type pointers.
|
||||
//
|
||||
typedef VOID *PVOID;
|
||||
typedef CHAR *PCHAR;
|
||||
typedef SHORT *PSHORT;
|
||||
typedef UCHAR *PUCHAR;
|
||||
typedef USHORT *PUSHORT;
|
||||
typedef ULONG *PULONG;
|
||||
|
||||
//
|
||||
// Long long type pointers.
|
||||
//
|
||||
typedef LONGLONG *PLONGLONG;
|
||||
typedef ULONGLONG *PULONGLONG;
|
||||
|
||||
//
|
||||
// Logical/boolean type pointers.
|
||||
//
|
||||
typedef ULONG *PLOGICAL;
|
||||
typedef BOOL *PBOOL;
|
||||
typedef BOOLEAN *PBOOLEAN;
|
||||
|
||||
//
|
||||
// String types.
|
||||
//
|
||||
@ -210,6 +208,16 @@ typedef NTSTATUS *PNTSTATUS;
|
||||
#define ALIGN_DOWN(x, a) ((x) & ~((a) - 1))
|
||||
#define ALIGN_UP(x, a) ALIGN_DOWN((x) + (a) - 1, a)
|
||||
|
||||
//
|
||||
// Bit extraction helpers.
|
||||
//
|
||||
#define LODWORD(x) ((ULONG)(x))
|
||||
#define HIDWORD(x) ((ULONG)((x) >> 32))
|
||||
#define LOWORD(x) ((USHORT)(x))
|
||||
#define HIWORD(x) ((USHORT)((x) >> 16))
|
||||
#define LOBYTE(x) ((UCHAR)(x))
|
||||
#define HIBYTE(x) ((UCHAR)((x) >> 8))
|
||||
|
||||
//
|
||||
// Large (64-bit) integer value.
|
||||
//
|
||||
@ -234,135 +242,6 @@ typedef union ULARGE_INTEGER {
|
||||
ULONGLONG QuadPart;
|
||||
} ULARGE_INTEGER, *PULARGE_INTEGER;
|
||||
|
||||
//
|
||||
// Doubly-linked list entry.
|
||||
//
|
||||
typedef struct _LIST_ENTRY {
|
||||
struct _LIST_ENTRY *Flink;
|
||||
struct _LIST_ENTRY *Blink;
|
||||
} LIST_ENTRY, *PLIST_ENTRY;
|
||||
|
||||
FORCEINLINE
|
||||
VOID
|
||||
InitializeListHead (
|
||||
IN PLIST_ENTRY Head
|
||||
)
|
||||
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Initializes a list head.
|
||||
|
||||
Arguments:
|
||||
|
||||
Head - the list head.
|
||||
|
||||
Return Value:
|
||||
|
||||
None.
|
||||
|
||||
--*/
|
||||
|
||||
{
|
||||
Head->Blink = Head;
|
||||
Head->Flink = Head;
|
||||
}
|
||||
|
||||
FORCEINLINE
|
||||
VOID
|
||||
InsertHeadList (
|
||||
IN PLIST_ENTRY Head,
|
||||
IN PLIST_ENTRY Entry
|
||||
)
|
||||
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Inserts a list entry at the head of a list.
|
||||
|
||||
Arguments:
|
||||
|
||||
Entry - The list entry.
|
||||
|
||||
Return Value:
|
||||
|
||||
None.
|
||||
|
||||
--*/
|
||||
|
||||
{
|
||||
Entry->Flink = Head->Flink;
|
||||
Entry->Blink = Head;
|
||||
Head->Flink->Blink = Entry;
|
||||
Head->Flink = Entry;
|
||||
}
|
||||
|
||||
FORCEINLINE
|
||||
VOID
|
||||
InsertTailList (
|
||||
IN PLIST_ENTRY Head,
|
||||
IN PLIST_ENTRY Entry
|
||||
)
|
||||
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Inserts a list entry at the tail of a list.
|
||||
|
||||
Arguments:
|
||||
|
||||
Entry - The list entry.
|
||||
|
||||
Return Value:
|
||||
|
||||
None.
|
||||
|
||||
--*/
|
||||
|
||||
{
|
||||
Entry->Blink = Head->Blink;
|
||||
Entry->Flink = Head;
|
||||
Head->Blink->Flink = Entry;
|
||||
Head->Blink = Entry;
|
||||
}
|
||||
|
||||
FORCEINLINE
|
||||
BOOLEAN
|
||||
RemoveEntryList (
|
||||
IN PLIST_ENTRY Entry
|
||||
)
|
||||
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Removes a list entry from a list.
|
||||
|
||||
Arguments:
|
||||
|
||||
Entry - the entry to remove.
|
||||
|
||||
Return Value:
|
||||
|
||||
True if the list is now empty,
|
||||
False if the list still has at least one entry.
|
||||
|
||||
--*/
|
||||
|
||||
{
|
||||
PLIST_ENTRY Blink, Flink;
|
||||
|
||||
Blink = Entry->Blink;
|
||||
Flink = Entry->Flink;
|
||||
Blink->Flink = Flink;
|
||||
Flink->Blink = Blink;
|
||||
|
||||
return (BOOLEAN)(Flink == Blink);
|
||||
}
|
||||
|
||||
//
|
||||
// Unicode string.
|
||||
//
|
||||
@ -377,6 +256,14 @@ typedef CONST UNICODE_STRING *PCUNICODE_STRING;
|
||||
|
||||
#define MAX_USTRING ALIGN_DOWN(MAXUSHORT, sizeof(WCHAR))
|
||||
|
||||
//
|
||||
// Doubly-linked list entry.
|
||||
//
|
||||
typedef struct _LIST_ENTRY {
|
||||
struct _LIST_ENTRY *Flink;
|
||||
struct _LIST_ENTRY *Blink;
|
||||
} LIST_ENTRY, *PLIST_ENTRY;
|
||||
|
||||
#include <guiddef.h>
|
||||
|
||||
#endif /* !_NTDEF_H */
|
||||
|
@ -19,7 +19,7 @@ Abstract:
|
||||
//
|
||||
// Machine type values.
|
||||
//
|
||||
#define IMAGE_FILE_MACHINE_UNKNOWN 0
|
||||
#define IMAGE_FILE_MACHINE_UNKNOWN 0x0000
|
||||
#define IMAGE_FILE_MACHINE_I386 0x014c
|
||||
#define IMAGE_FILE_MACHINE_AMD64 0x8664
|
||||
|
||||
|
@ -16,9 +16,9 @@ Abstract:
|
||||
#ifndef _NTRTL_H
|
||||
#define _NTRTL_H
|
||||
|
||||
#include <string.h>
|
||||
#include <ntdef.h>
|
||||
#include <ntstatus.h>
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//
|
||||
// Memory operations.
|
||||
@ -28,7 +28,128 @@ Abstract:
|
||||
#define RtlFillMemory(Destination, Length, Fill) memset((Destination), (Fill), (Length))
|
||||
#define RtlZeroMemory(Destination, Length) memset((Destination), 0, (Length))
|
||||
|
||||
#define ULONG_ERROR 0xFFFFFFFFUL
|
||||
FORCEINLINE
|
||||
VOID
|
||||
InitializeListHead (
|
||||
IN PLIST_ENTRY Head
|
||||
)
|
||||
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Initializes a list head.
|
||||
|
||||
Arguments:
|
||||
|
||||
Head - Pointer to the list's head.
|
||||
|
||||
Return Value:
|
||||
|
||||
None.
|
||||
|
||||
--*/
|
||||
|
||||
{
|
||||
Head->Blink = Head;
|
||||
Head->Flink = Head;
|
||||
}
|
||||
|
||||
FORCEINLINE
|
||||
VOID
|
||||
InsertHeadList (
|
||||
IN PLIST_ENTRY Head,
|
||||
IN PLIST_ENTRY Entry
|
||||
)
|
||||
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Inserts an entry at the head of a list.
|
||||
|
||||
Arguments:
|
||||
|
||||
Entry - Pointer to the list entry to insert.
|
||||
|
||||
Return Value:
|
||||
|
||||
None.
|
||||
|
||||
--*/
|
||||
|
||||
{
|
||||
Entry->Flink = Head->Flink;
|
||||
Entry->Blink = Head;
|
||||
Head->Flink->Blink = Entry;
|
||||
Head->Flink = Entry;
|
||||
}
|
||||
|
||||
FORCEINLINE
|
||||
VOID
|
||||
InsertTailList (
|
||||
IN PLIST_ENTRY Head,
|
||||
IN PLIST_ENTRY Entry
|
||||
)
|
||||
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Inserts an entry at the tail of a list.
|
||||
|
||||
Arguments:
|
||||
|
||||
Entry - Pointer to the list entry to insert.
|
||||
|
||||
Return Value:
|
||||
|
||||
None.
|
||||
|
||||
--*/
|
||||
|
||||
{
|
||||
Entry->Blink = Head->Blink;
|
||||
Entry->Flink = Head;
|
||||
Head->Blink->Flink = Entry;
|
||||
Head->Blink = Entry;
|
||||
}
|
||||
|
||||
FORCEINLINE
|
||||
BOOLEAN
|
||||
RemoveEntryList (
|
||||
IN PLIST_ENTRY Entry
|
||||
)
|
||||
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Removes an entry from a list.
|
||||
|
||||
Arguments:
|
||||
|
||||
Entry - Pointer to the entry to remove.
|
||||
|
||||
Return Value:
|
||||
|
||||
TRUE if the list is now empty,
|
||||
FALSE if the list still has at least one entry.
|
||||
|
||||
--*/
|
||||
|
||||
{
|
||||
PLIST_ENTRY Blink, Flink;
|
||||
|
||||
Blink = Entry->Blink;
|
||||
Flink = Entry->Flink;
|
||||
Blink->Flink = Flink;
|
||||
Flink->Blink = Blink;
|
||||
|
||||
return (BOOLEAN)(Flink == Blink);
|
||||
}
|
||||
|
||||
#define ULONG_ERROR 0xffffffffUL
|
||||
|
||||
FORCEINLINE
|
||||
NTSTATUS
|
||||
@ -83,4 +204,8 @@ RtlGUIDFromString (
|
||||
OUT GUID *Guid
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !_NTRTL_H */
|
||||
|
@ -13,8 +13,7 @@ Abstract:
|
||||
|
||||
--*/
|
||||
|
||||
#include <ntrtl.h>
|
||||
#include <ntstatus.h>
|
||||
#include <nt.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
int
|
||||
|
@ -13,7 +13,7 @@ Abstract:
|
||||
|
||||
--*/
|
||||
|
||||
#include <ntrtl.h>
|
||||
#include <nt.h>
|
||||
#include <wchar.h>
|
||||
|
||||
VOID
|
||||
@ -32,9 +32,9 @@ Routine Description:
|
||||
|
||||
Arguments:
|
||||
|
||||
Destination - A pointer to the unicode string structure.
|
||||
Destination - Pointer to the unicode string structure.
|
||||
|
||||
Source - Optionally, a pointer to a null-terminated string to initialize
|
||||
Source - Optionally, a pointer to a NULL-terminated string to initialize
|
||||
the unicode string structure with.
|
||||
|
||||
Return Value:
|
||||
|
Loading…
Reference in New Issue
Block a user