feat(profile): add stddef.h and profile-gated string.h

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <[email protected]>
This commit is contained in:
2026-08-31 19:57:21 -04:00
co-authored by Sisyphus
parent 060fc03ab7
commit ace9728565
2 changed files with 147 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
#ifndef VLIBC_STDDEF_H
#define VLIBC_STDDEF_H
/*
* vlibc — <stddef.h>.
*
* Self-contained definitions of the common C types and macros (C23). Every
* definition here is derived from compiler builtins, so this header never
* borrows from a system header.
*
* The compatibility profile is exposed by include/vlibc/features.h; it is
* included here so consumers always see the configured VLIBC_LEVEL.
*/
#include <vlibc/features.h>
/* Integer type of the result of the sizeof operator. */
typedef __SIZE_TYPE__ size_t;
/* Signed integer type of the difference of two pointers. */
typedef __PTRDIFF_TYPE__ ptrdiff_t;
/* Wide character type. */
typedef __WCHAR_TYPE__ wchar_t;
/* Type of the null pointer constant nullptr (C23). */
typedef typeof(nullptr) nullptr_t;
/* Null pointer constant. */
#define NULL ((void *)0)
/* Offset in bytes of a member from the start of its enclosing object. */
#define offsetof(type, m) __builtin_offsetof(type, m)
/*
* An object type whose alignment is as great as that of any supported
* fundamental type; suitable as the storage type for aligned allocation.
*/
typedef struct
{
long long vll;
long double vld;
} max_align_t;
#endif /* VLIBC_STDDEF_H */
+102
View File
@@ -0,0 +1,102 @@
#ifndef VLIBC_STRING_H
#define VLIBC_STRING_H
/*
* vlibc — <string.h>.
*
* String and memory functions, gated by the active compatibility profile
* (see include/vlibc/features.h). Levels are cumulative:
*
* Level 1 (onlyposix): ISO C core — memcpy, memmove, memset, strlen, strcmp.
* Level 2 (muslmimic): BSD extensions — strlcpy, strlcat.
* Level 3 (muslext): GNU extensions — strcasestr.
*
* This header includes <vlibc/features.h> itself, so the gates below always
* see the configured VLIBC_LEVEL even when the caller included no vlibc
* header first, and <stddef.h> for size_t.
*/
#include <vlibc/features.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Level 1: ISO C core (always present). */
/*
* Return the length of s, excluding the terminating NUL.
* pure: reads memory, no side effects.
*/
__attribute__((pure)) size_t
strlen(const char *s);
/*
* Compare the strings lhs and rhs; return negative, zero, or positive when
* lhs is less than, equal to, or greater than rhs.
* pure: reads memory, no side effects.
*/
__attribute__((pure)) int
strcmp(const char *lhs, const char *rhs);
/*
* Copy n bytes from src to dst. The regions must not overlap (restrict).
* No intent attribute: it writes memory.
*/
void *
memcpy(void *restrict dst, const void *restrict src, size_t n);
/*
* Copy n bytes from src to dst. The regions may overlap, so the parameters
* are deliberately not restrict.
* No intent attribute: it writes memory.
*/
void *
memmove(void *dst, const void *src, size_t n);
/*
* Fill n bytes at dst with c (converted to unsigned char).
* No intent attribute: it writes memory.
*/
void *
memset(void *dst, int c, size_t n);
#if VLIBC_LEVEL >= 2
/* Level 2 (muslmimic): BSD extensions. */
/*
* Copy at most size - 1 bytes from src to dst and NUL-terminate the result;
* return strlen(src). No NUL is written when size is 0.
* No intent attribute: it writes memory.
*/
size_t
strlcpy(char *dst, const char *src, size_t size);
/*
* Append src to dst, NUL-terminating within size bytes; return the length of
* the string that would have been created without truncation.
* No intent attribute: it writes memory.
*/
size_t
strlcat(char *dst, const char *src, size_t size);
#endif /* VLIBC_LEVEL >= 2 */
#if VLIBC_LEVEL >= 3
/* Level 3 (muslext): GNU extensions. */
/*
* Return a pointer to the first case-insensitive (ASCII fold) occurrence of
* needle in haystack, or NULL if absent; an empty needle matches haystack.
* pure: reads memory, no side effects.
*/
__attribute__((pure)) char *
strcasestr(const char *haystack, const char *needle);
#endif /* VLIBC_LEVEL >= 3 */
#ifdef __cplusplus
}
#endif
#endif /* VLIBC_STRING_H */