Add SDK/CRT string routines and headers
This commit is contained in:
parent
70489d6d39
commit
8ff7a75afc
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);
|
||||
}
|
37
premake5.lua
37
premake5.lua
@ -3,27 +3,44 @@
|
||||
--- Provided under the BSD 3-Clause license.
|
||||
---
|
||||
|
||||
workspace("LibreXP")
|
||||
workspace("Alcyone")
|
||||
configurations({ "DEBUG", "RELEASE" })
|
||||
language("C")
|
||||
toolset("clang")
|
||||
configurations({ "Debug", "Release" })
|
||||
system("windows")
|
||||
warnings("Extra")
|
||||
|
||||
filter("configurations:Debug")
|
||||
defines({ "DEBUG" })
|
||||
filter("configurations:DEBUG")
|
||||
symbols("On")
|
||||
defines({ "_DEBUG" })
|
||||
|
||||
filter("configurations:Release")
|
||||
defines({ "NDEBUG" })
|
||||
optimize("On")
|
||||
filter("configurations:RELEASE")
|
||||
optimize("Speed")
|
||||
|
||||
filter("toolset:clang")
|
||||
buildoptions({ "-target x86_64-windows-unknown", "-ffreestanding" })
|
||||
linkoptions({ "-target x86_64-windows-unknown", "-fuse-ld=lld-link", "-Wl,-nodefaultlib" })
|
||||
|
||||
project("CRT")
|
||||
kind("StaticLib")
|
||||
location("SDK/CRT")
|
||||
|
||||
includedirs({ "SDK/CRT/INC" })
|
||||
objdir("BUILD/SDK/CRT")
|
||||
targetdir("BUILD/SDK")
|
||||
targetname("crt")
|
||||
files({ "SDK/CRT/INC/**.h", "SDK/CRT/**.c" })
|
||||
|
||||
--[[
|
||||
project("BOOT")
|
||||
kind("ConsoleApp")
|
||||
|
||||
includedirs({ "BOOT/ENVIRON/INC" })
|
||||
includedirs({ "BOOT/ENVIRON/INC", "SDK/INC/CRT" })
|
||||
objdir("BUILD/BOOT")
|
||||
targetdir("BUILD/BOOT")
|
||||
files({ "BOOT/ENVIRON/INC/**.h", "BOOT/ENVIRON/**.c" })
|
||||
|
||||
filter("toolset:clang")
|
||||
buildoptions({ "-target x86_64-windows-unknown", "-Wall", "-Wextra", "-O2", "-ffreestanding", "-fshort-wchar", "-fno-strict-aliasing", "-fno-stack-protector", "-fno-stack-check", "-mno-red-zone" })
|
||||
linkoptions({ "-target x86_64-windows-unknown", "-fuse-ld=lld-link", "-Wl,-subsystem:efi_application", "-Wl,-entry:EfiEntry", "-Wl,-nodefaultlib" })
|
||||
buildoptions({ "-fshort-wchar", "-fno-strict-aliasing", "-fno-stack-protector", "-fno-stack-check", "-mno-red-zone" })
|
||||
linkoptions({ "-Wl,-subsystem:efi_application", "-Wl,-entry:EfiEntry", "crt.lib" })
|
||||
--]]
|
||||
|
Loading…
Reference in New Issue
Block a user