Add SDK/CRT string routines and headers
This commit is contained in:
60
SDK/CRT/INC/stddef.h
Normal file
60
SDK/CRT/INC/stddef.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/*++
|
||||
|
||||
Copyright (c) 2024, Quinn Stephens.
|
||||
Provided under the BSD 3-Clause license.
|
||||
|
||||
Module Name:
|
||||
|
||||
stddef.h
|
||||
|
||||
Abstract:
|
||||
|
||||
Provides standard types and definitions.
|
||||
|
||||
--*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _STDDEF_H
|
||||
#define _STDDEF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef NULL
|
||||
#ifdef __cplusplus
|
||||
#define NULL 0
|
||||
#else
|
||||
#define NULL ((void*)0)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef _SIZE_T_DEFINED
|
||||
#define _SIZE_T_DEFINED
|
||||
#ifdef _WIN64
|
||||
typedef unsigned __int64 size_t;
|
||||
#else
|
||||
typedef unsigned int size_t;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef _PTRDIFF_T_DEFINED
|
||||
#define _PTRDIFF_T_DEFINED
|
||||
#ifdef _WIN64
|
||||
typedef __int64 ptrdiff_t;
|
||||
#else
|
||||
typedef long int ptrdiff_t;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef _WCHAR_T_DEFINED
|
||||
#define _WCHAR_T_DEFINED
|
||||
typedef unsigned short wchar_t;
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !_STDDEF_H */
|
37
SDK/CRT/INC/string.h
Normal file
37
SDK/CRT/INC/string.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*++
|
||||
|
||||
Copyright (c) 2024, Quinn Stephens.
|
||||
Provided under the BSD 3-Clause license.
|
||||
|
||||
Module Name:
|
||||
|
||||
string.h
|
||||
|
||||
Abstract:
|
||||
|
||||
Provides definitions for string routines.
|
||||
|
||||
--*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _STRING_H
|
||||
#define _STRING_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
size_t strlen(const char *str);
|
||||
size_t strnlen(const char *str, size_t maxlen);
|
||||
|
||||
void *memset(void *dest, int c, size_t count);
|
||||
void *memcpy(void *dest, const void *src, size_t count);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !_STRING_H */
|
37
SDK/CRT/INC/wchar.h
Normal file
37
SDK/CRT/INC/wchar.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*++
|
||||
|
||||
Copyright (c) 2024, Quinn Stephens.
|
||||
Provided under the BSD 3-Clause license.
|
||||
|
||||
Module Name:
|
||||
|
||||
wchar.h
|
||||
|
||||
Abstract:
|
||||
|
||||
Provides definitions for wide string routines.
|
||||
|
||||
--*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _WCHAR_H
|
||||
#define _WCHAR_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
size_t wcslen(const wchar_t *str);
|
||||
size_t wcsnlen(const wchar_t *str, size_t maxlen);
|
||||
|
||||
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);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !_WCHAR_H */
|
53
SDK/CRT/STRING/mem.c
Normal file
53
SDK/CRT/STRING/mem.c
Normal file
@@ -0,0 +1,53 @@
|
||||
/*++
|
||||
|
||||
Copyright (c) 2024, Quinn Stephens.
|
||||
Provided under the BSD 3-Clause license.
|
||||
|
||||
Module Name:
|
||||
|
||||
mem.c
|
||||
|
||||
Abstract:
|
||||
|
||||
Provides memory manipulation routines.
|
||||
|
||||
--*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void *
|
||||
memset (
|
||||
void *dest,
|
||||
int c,
|
||||
size_t count
|
||||
)
|
||||
|
||||
{
|
||||
void *ptr = dest;
|
||||
|
||||
while (count--) {
|
||||
*(char *)dest = (char)c;
|
||||
dest = (char *)dest + 1;
|
||||
}
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void *
|
||||
memcpy (
|
||||
void *dest,
|
||||
const void *src,
|
||||
size_t count
|
||||
)
|
||||
|
||||
{
|
||||
void *ptr = dest;
|
||||
|
||||
while (count--) {
|
||||
*(char *)dest = *(char *)src;
|
||||
dest = (char *)dest + 1;
|
||||
src = (char *)src + 1;
|
||||
}
|
||||
|
||||
return ptr;
|
||||
}
|
45
SDK/CRT/STRING/str.c
Normal file
45
SDK/CRT/STRING/str.c
Normal file
@@ -0,0 +1,45 @@
|
||||
/*++
|
||||
|
||||
Copyright (c) 2024, Quinn Stephens.
|
||||
Provided under the BSD 3-Clause license.
|
||||
|
||||
Module Name:
|
||||
|
||||
str.c
|
||||
|
||||
Abstract:
|
||||
|
||||
Provides string manipulation routines.
|
||||
|
||||
--*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
size_t
|
||||
strlen (
|
||||
const char *str
|
||||
)
|
||||
|
||||
{
|
||||
const char *ptr;
|
||||
|
||||
ptr = str;
|
||||
while (*ptr++);
|
||||
|
||||
return ptr - str - sizeof(char);
|
||||
}
|
||||
|
||||
size_t
|
||||
strnlen (
|
||||
const char *str,
|
||||
size_t maxlen
|
||||
)
|
||||
|
||||
{
|
||||
size_t len;
|
||||
|
||||
len = 0;
|
||||
while (len < maxlen && str[len++]);
|
||||
|
||||
return len - sizeof(char);
|
||||
}
|
53
SDK/CRT/STRING/wmem.c
Normal file
53
SDK/CRT/STRING/wmem.c
Normal file
@@ -0,0 +1,53 @@
|
||||
/*++
|
||||
|
||||
Copyright (c) 2024, Quinn Stephens.
|
||||
Provided under the BSD 3-Clause license.
|
||||
|
||||
Module Name:
|
||||
|
||||
wmem.c
|
||||
|
||||
Abstract:
|
||||
|
||||
Provides wide memory manipulation routines.
|
||||
|
||||
--*/
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
wchar_t *
|
||||
wmemset (
|
||||
wchar_t *dest,
|
||||
wchar_t c,
|
||||
size_t count
|
||||
)
|
||||
|
||||
{
|
||||
void *ptr = dest;
|
||||
|
||||
while (count--) {
|
||||
*(wchar_t *)dest = c;
|
||||
dest = (wchar_t *)dest + 1;
|
||||
}
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
wchar_t *
|
||||
wmemcpy (
|
||||
wchar_t *dest,
|
||||
const wchar_t *src,
|
||||
size_t count
|
||||
)
|
||||
|
||||
{
|
||||
void *ptr = dest;
|
||||
|
||||
while (count--) {
|
||||
*(wchar_t *)dest = *(wchar_t *)src;
|
||||
dest = (wchar_t *)dest + 1;
|
||||
src = (wchar_t *)src + 1;
|
||||
}
|
||||
|
||||
return ptr;
|
||||
}
|
45
SDK/CRT/STRING/wstr.c
Normal file
45
SDK/CRT/STRING/wstr.c
Normal file
@@ -0,0 +1,45 @@
|
||||
/*++
|
||||
|
||||
Copyright (c) 2024, Quinn Stephens.
|
||||
Provided under the BSD 3-Clause license.
|
||||
|
||||
Module Name:
|
||||
|
||||
wstr.c
|
||||
|
||||
Abstract:
|
||||
|
||||
Provides wide string manipulation routines.
|
||||
|
||||
--*/
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
size_t
|
||||
wcslen (
|
||||
const wchar_t *str
|
||||
)
|
||||
|
||||
{
|
||||
const wchar_t *ptr;
|
||||
|
||||
ptr = str;
|
||||
while (*ptr++);
|
||||
|
||||
return (const char*)ptr - (const char*)str - sizeof(wchar_t);
|
||||
}
|
||||
|
||||
size_t
|
||||
wcsnlen (
|
||||
const wchar_t *str,
|
||||
size_t maxlen
|
||||
)
|
||||
|
||||
{
|
||||
size_t len;
|
||||
|
||||
len = 0;
|
||||
while (len < maxlen && str[len++]);
|
||||
|
||||
return len - sizeof(wchar_t);
|
||||
}
|
Reference in New Issue
Block a user