user: implement mlibc as the libc, finally.

It's finally done..

Signed-off-by: kaguya <vpshinomiya@protonmail.com>
This commit is contained in:
kaguya
2026-05-02 03:31:49 -04:00
parent 2fa39ad85a
commit 9a9b91c940
2387 changed files with 152741 additions and 315 deletions
+10
View File
@@ -0,0 +1,10 @@
#ifndef MLIBC_FD_SET_H
#define MLIBC_FD_SET_H
#include <bits/types.h>
typedef struct {
__mlibc_uint8 fds_bits[128];
} fd_set;
#endif /* MLIBC_FD_SET_H */
+6
View File
@@ -0,0 +1,6 @@
#ifndef _MLIBC_ID_T_H
#define _MLIBC_ID_T_H
typedef unsigned int id_t;
#endif /* _MLIBC_ID_T_H */
@@ -0,0 +1,8 @@
#ifndef MLIBC_IN_ADDR_H
#define MLIBC_IN_ADDR_H
#include <stdint.h>
typedef uint32_t in_addr_t;
#endif /* MLIBC_IN_ADDR_H */
@@ -0,0 +1,8 @@
#ifndef MLIBC_IN_PORT_H
#define MLIBC_IN_PORT_H
#include <stdint.h>
typedef uint16_t in_port_t;
#endif /* MLIBC_IN_PORT_H */
+11
View File
@@ -0,0 +1,11 @@
#ifndef MLIBC_IOVEC_H
#define MLIBC_IOVEC_H
#include <bits/types.h>
struct iovec {
void *iov_base;
__mlibc_size iov_len;
};
#endif /* MLIBC_IOVEC_H */
@@ -0,0 +1,14 @@
#ifndef _LOCALE_T_H
#define _LOCALE_T_H
#ifdef __cplusplus
extern "C" {
#endif
typedef void *locale_t;
#ifdef __cplusplus
}
#endif
#endif /* _LOCALE_T_H */
@@ -0,0 +1,36 @@
#ifndef _POSIX_CTYPE_H
#define _POSIX_CTYPE_H
#ifdef __cplusplus
extern "C" {
#endif
#include <bits/posix/locale_t.h>
#ifndef __MLIBC_ABI_ONLY
int isalnum_l(int __c, locale_t __loc);
int isalpha_l(int __c, locale_t __loc);
int isblank_l(int __c, locale_t __loc);
int iscntrl_l(int __c, locale_t __loc);
int isdigit_l(int __c, locale_t __loc);
int isgraph_l(int __c, locale_t __loc);
int islower_l(int __c, locale_t __loc);
int isprint_l(int __c, locale_t __loc);
int ispunct_l(int __c, locale_t __loc);
int isspace_l(int __c, locale_t __loc);
int isupper_l(int __c, locale_t __loc);
int isxdigit_l(int __c, locale_t __loc);
int isascii_l(int __c, locale_t __loc);
int tolower_l(int __c, locale_t __loc);
int toupper_l(int __c, locale_t __loc);
#endif /* !__MLIBC_ABI_ONLY */
#ifdef __cplusplus
}
#endif
#endif /* _POSIX_CTYPE_H */
@@ -0,0 +1,23 @@
#ifndef MLIBC_POSIX_LOCALE_H
#define MLIBC_POSIX_LOCALE_H
#include <bits/posix/locale_t.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __MLIBC_ABI_ONLY
locale_t newlocale(int __category_mask, const char *__locale, locale_t __base);
void freelocale(locale_t __locobj);
locale_t uselocale(locale_t __locobj);
locale_t duplocale(locale_t __locobj);
#endif /* !__MLIBC_ABI_ONLY */
#ifdef __cplusplus
}
#endif
#endif /* MLIBC_POSIX_LOCALE_H */
@@ -0,0 +1,113 @@
#ifndef MLIBC_POSIX_SIGNAL_H
#define MLIBC_POSIX_SIGNAL_H
#ifdef __cplusplus
extern "C" {
#endif
#include <bits/ansi/time_t.h>
#include <bits/ansi/timespec.h>
#include <bits/posix/pthread_t.h>
#include <bits/sigset_t.h>
#include <stddef.h>
#include <stdint.h>
#include <mlibc-config.h>
#define FPE_INTDIV 1 /* integer divide by zero */
#define FPE_INTOVF 2 /* integer overflow */
#define FPE_FLTDIV 3 /* floating point divide by zero */
#define FPE_FLTOVF 4 /* floating point overflow */
#define FPE_FLTUND 5 /* floating point underflow */
#define FPE_FLTRES 6 /* floating point inexact result */
#define FPE_FLTINV 7 /* floating point invalid operation */
#define FPE_FLTSUB 8 /* subscript out of range */
#define TRAP_BRKPT 1 /* process breakpoint */
#define TRAP_TRACE 2 /* process trace trap */
#if defined(__x86_64__)
/* Start Glibc stuff */
struct _libc_fpxreg {
unsigned short int significand[4];
unsigned short int exponent;
unsigned short int __glibc_reserved1[3];
};
struct _libc_xmmreg {
uint32_t element[4];
};
struct _libc_fpstate {
uint16_t cwd;
int16_t swd;
uint16_t ftw;
uint16_t fop;
uint64_t rip;
uint64_t dp;
uint32_t mxcsr;
uint32_t mxcr_mask;
struct _libc_fpxreg _st[8];
struct _libc_xmmreg _xmm[16];
uint32_t __glibc_reserved1[24];
};
typedef struct _libc_fpstate *fpregset_t;
/* End Glibc stuff */
typedef unsigned long int greg_t;
#endif
#define FPE_INTDIV 1 /* integer divide by zero */
#define FPE_INTOVF 2 /* integer overflow */
#define FPE_FLTDIV 3 /* floating point divide by zero */
#define FPE_FLTOVF 4 /* floating point overflow */
#define FPE_FLTUND 5 /* floating point underflow */
#define FPE_FLTRES 6 /* floating point inexact result */
#define FPE_FLTINV 7 /* floating point invalid operation */
#define FPE_FLTSUB 8 /* subscript out of range */
#define TRAP_BRKPT 1 /* process breakpoint */
#define TRAP_TRACE 2 /* process trace trap */
#ifndef __MLIBC_ABI_ONLY
/* functions to block / wait for signals */
int sigsuspend(const sigset_t *__sigmask);
int sigprocmask(int __how, const sigset_t *__restrict __sigmask, sigset_t *__restrict __oldmask);
int pthread_sigmask(int __how, const sigset_t *__restrict __sigmask, sigset_t *__restrict __oldmask);
int pthread_kill(pthread_t __thrd, int __sig);
/* functions to handle signals */
int sigaction(int __signum, const struct sigaction *__restrict __act, struct sigaction *__restrict __oldact);
int sigpending(sigset_t *__set);
int siginterrupt(int __sig, int __flag);
int sigaltstack(const stack_t *__restrict __ss, stack_t *__restrict __oss);
/* functions to raise signals */
int kill(pid_t __pid, int __number);
int killpg(int __pgrp, int __sig);
int sigtimedwait(const sigset_t *__restrict __set, siginfo_t *__restrict __info, const struct timespec *__restrict __timeout);
int sigwait(const sigset_t *__restrict __set, int *__restrict __sig);
int sigwaitinfo(const sigset_t *__restrict __set, siginfo_t *__restrict __info);
/* Glibc extension */
#if __MLIBC_GLIBC_OPTION
int sigisemptyset(const sigset_t *__set);
#endif /* __MLIBC_GLIBC_OPTION */
int sigqueue(pid_t __pid, int __sig, const union sigval __value);
#endif /* !__MLIBC_ABI_ONLY */
#ifdef __cplusplus
}
#endif
#endif /* MLIBC_POSIX_SIGNAL_H */
@@ -0,0 +1,76 @@
#ifndef MLIBC_POSIX_STDIO_H
#define MLIBC_POSIX_STDIO_H
#include <bits/off_t.h>
#include <bits/size_t.h>
#include <bits/ssize_t.h>
#include <bits/file.h>
/* MISSING: var_list */
#ifdef __cplusplus
extern "C" {
#endif
#define P_tmpdir "/tmp"
#ifndef __MLIBC_ABI_ONLY
int fileno(FILE *__file);
FILE *fdopen(int __fd, const char *__mode);
FILE *fmemopen(void *__restrict __buf, size_t __size, const char *__restrict __mode);
int pclose(FILE *__file);
FILE *popen(const char *__command, const char *__type);
FILE *open_memstream(char **__buf, size_t *__sizeloc);
int fseeko(FILE *__stream, off_t __offset, int __whence);
int fseeko64(FILE *__stream, off64_t __offset, int __whence);
off_t ftello(FILE *__stream);
off64_t ftello64(FILE *__stream);
__attribute__((format(__printf__, 2, 3))) int dprintf(int __fd, const char *__format, ...);
__attribute__((format(__printf__, 2, 0)))
int vdprintf(int __fd, const char *__format, __builtin_va_list __args);
char *fgetln(FILE *__stream, size_t *__size);
char *tempnam(const char *__dir, const char *__pfx);
#endif /* !__MLIBC_ABI_ONLY */
#define RENAME_EXCHANGE (1 << 1)
/* GNU extensions */
typedef ssize_t (cookie_read_function_t)(void *__cookie, char *__buffer, size_t __size);
typedef ssize_t (cookie_write_function_t)(void *__cookie, const char *__buffer, size_t __size);
typedef int (cookie_seek_function_t)(void *__cookie, off_t *, int);
typedef int (cookie_close_function_t)(void *__cookie);
typedef struct _IO_cookie_io_functions_t {
cookie_read_function_t *read;
cookie_write_function_t *write;
cookie_seek_function_t *seek;
cookie_close_function_t *close;
} cookie_io_functions_t;
#ifndef __MLIBC_ABI_ONLY
#if defined(_GNU_SOURCE)
FILE *fopencookie(void *__restrict __cookie, const char *__restrict __mode, cookie_io_functions_t __io_funcs);
#endif /* defined(_GNU_SOURCE) */
#endif /* !__MLIBC_ABI_ONLY */
#ifdef __cplusplus
}
#endif
/* MISSING: various functions and macros */
#endif /* MLIBC_POSIX_STDIO_H */
@@ -0,0 +1,77 @@
#ifndef MLIBC_POSIX_STDLIB_H
#define MLIBC_POSIX_STDLIB_H
#include <bits/posix/locale_t.h>
#include <bits/size_t.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __MLIBC_ABI_ONLY
long random(void);
double drand48(void);
double erand48(unsigned short __s[3]);
unsigned short *seed48(unsigned short __s[3]);
void srand48(long int __seed);
long int mrand48(void);
long jrand48(unsigned short __s[3]);
char *initstate(unsigned int __seed, char *__state, size_t __size);
char *setstate(char *__state);
void srandom(unsigned int __seed);
/* ---------------------------------------------------------------------------- */
/* Environment. */
/* ---------------------------------------------------------------------------- */
int putenv(char *__string);
int setenv(const char *__name, const char *__value, int __overwrite);
int unsetenv(const char *__name);
/* ---------------------------------------------------------------------------- */
/* Path handling. */
/* ---------------------------------------------------------------------------- */
int mkstemp(char *__pattern);
int mkstemps(char *__pattern, int __suffixlen);
int mkostemp(char *__pattern, int __flags);
int mkostemps(char *__pattern, int __suffixlen, int __flags);
char *mkdtemp(char *__path);
char *realpath(const char *__restrict __path, char *__restrict __out);
/* ---------------------------------------------------------------------------- */
/* Pseudoterminals */
/* ---------------------------------------------------------------------------- */
int posix_openpt(int __flags);
int grantpt(int __fd);
int unlockpt(int __fd);
char *ptsname(int __fd);
int ptsname_r(int __fd, char *__buf, size_t __len);
double strtod_l(const char *__restrict__ __nptr, char ** __restrict__ __endptr, locale_t __loc);
long double strtold_l(const char *__restrict__ __nptr, char ** __restrict__ __endptr, locale_t __loc);
float strtof_l(const char *__restrict __string, char **__restrict __end, locale_t __loc);
int getsubopt(char **__restrict__ __optionp, char *const *__restrict__ __tokens, char **__restrict__ __valuep);
/* GNU extension */
char *secure_getenv(const char *__name);
char *canonicalize_file_name(const char *__name);
/* BSD extension */
void *reallocarray(void *__ptr, size_t __count, size_t __size);
int clearenv(void);
#endif /* !__MLIBC_ABI_ONLY */
#ifdef __cplusplus
}
#endif
#endif /* MLIBC_POSIX_STDLIB_H */
@@ -0,0 +1,59 @@
#ifndef MLIBC_POSIX_STRING_H
#define MLIBC_POSIX_STRING_H
#include <alloca.h>
#include <bits/posix/locale_t.h>
#include <bits/size_t.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __MLIBC_ABI_ONLY
char *strdup(const char *__string);
char *strndup(const char *__string, size_t __max_size);
size_t strnlen(const char *__s, size_t __max_size);
char *strtok_r(char *__restrict __s, const char *__restrict __delim, char **__restrict __ptr);
char *strsep(char **__stringp, const char *__delim);
char *strsignal(int __sig);
char *stpcpy(char *__restrict __dest, const char *__restrict __src);
char *stpncpy(char *__restrict __dest, const char *__restrict __src, size_t __n);
void *memccpy(void *__restrict __dest, const void *__restrict __src, int __c, size_t __n);
int strcoll_l(const char *__s1, const char *__s2, locale_t __locale);
char *strerror_l(int __errnum, locale_t __locale);
/* GNU extensions. */
#if defined(_GNU_SOURCE)
char *strcasestr(const char *__s1, const char *__s2);
#define strdupa(x) ({ \
const char *__str = (x); \
size_t __len = strlen(__str) + 1; \
char *__buf = alloca(__len); \
(char *) memcpy(__buf, __str, __len); \
})
#define strndupa(x, y) ({ \
const char *__str = (x); \
size_t __len = strnlen(__str, (y)) + 1; \
char *__buf = alloca(__len); \
__buf[__len - 1] = '\0'; \
(char *) memcpy(__buf, __str, __len - 1); \
})
void *memrchr(const void *__m, int __c, size_t __n);
#endif /* defined(_GNU_SOURCE) */
/* BSD extensions */
size_t strlcpy(char *__d, const char *__s, size_t __n);
size_t strlcat(char *__d, const char *__s, size_t __n);
#endif /* !__MLIBC_ABI_ONLY */
#ifdef __cplusplus
}
#endif
#endif /* MLIBC_POSIX_STRING_H */
@@ -0,0 +1,43 @@
#ifndef MLIBC_POSIX_TIME_H
#define MLIBC_POSIX_TIME_H
#include <abi-bits/clockid_t.h>
#include <abi-bits/sigevent.h>
#include <bits/ansi/timespec.h>
#include <bits/posix/timer_t.h>
#include <bits/posix/timeval.h>
#define TIMER_ABSTIME 1
#ifdef __cplusplus
extern "C" {
#endif
struct itimerspec {
struct timespec it_interval;
struct timespec it_value;
};
#ifndef __MLIBC_ABI_ONLY
int timer_getoverrun(timer_t __timerid);
int utimes(const char *__filename, const struct timeval __tv[2]);
/* Not standardized, Linux and BSDs have it */
int futimes(int __fd, const struct timeval __tv[2]);
int lutimes(const char *__filename, const struct timeval __tv[2]);
int timer_create(clockid_t __clockid, struct sigevent *__restrict __sevp, timer_t *__restrict __timerid);
int timer_settime(timer_t __timerid, int __flags, const struct itimerspec *__restrict __new_value,
struct itimerspec *__restrict __old_value);
int timer_gettime(timer_t __timerid, struct itimerspec *__curr_value);
int timer_delete(timer_t __timerid);
#endif /* !__MLIBC_ABI_ONLY */
#ifdef __cplusplus
}
#endif
#endif /* MLIBC_POSIX_TIME_H */
@@ -0,0 +1,43 @@
#ifndef _POSIX_WCTYPE_H
#define _POSIX_WCTYPE_H
#include <bits/posix/locale_t.h>
#include <bits/wint_t.h>
#include <bits/wctype_t.h>
#include <bits/wctrans_t.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __MLIBC_ABI_ONLY
int iswalnum_l(wint_t __wc, locale_t __loc);
int iswblank_l(wint_t __wc, locale_t __loc);
int iswcntrl_l(wint_t __wc, locale_t __loc);
int iswdigit_l(wint_t __wc, locale_t __loc);
int iswgraph_l(wint_t __wc, locale_t __loc);
int iswlower_l(wint_t __wc, locale_t __loc);
int iswprint_l(wint_t __wc, locale_t __loc);
int iswpunct_l(wint_t __wc, locale_t __loc);
int iswspace_l(wint_t __wc, locale_t __loc);
int iswupper_l(wint_t __wc, locale_t __loc);
int iswxdigit_l(wint_t __wc, locale_t __loc);
int iswalpha_l(wint_t __wc, locale_t __loc);
wctype_t wctype_l(const char *__string, locale_t __loc);
int iswctype_l(wint_t __wc, wctype_t __type, locale_t __loc);
wint_t towlower_l(wint_t __wc, locale_t __loc);
wint_t towupper_l(wint_t __wc, locale_t __loc);
wctrans_t wctrans_l(const char *__string, locale_t __loc);
wint_t towctrans_l(wint_t __wc, wctrans_t __trans, locale_t __loc);
#endif /* !__MLIBC_ABI_ONLY */
#ifdef __cplusplus
}
#endif
#endif /* _POSIX_WCTYPE_H */
@@ -0,0 +1,8 @@
#ifndef _MLIBC_BITS_PTHREAD_T_HPP
#define _MLIBC_BITS_PTHREAD_T_HPP
#include <bits/threads.h>
typedef struct __mlibc_thread_data *pthread_t;
#endif /* _MLIBC_BITS_PTHREAD_T_HPP */
+24
View File
@@ -0,0 +1,24 @@
#ifndef MLIBC_STAT_H
#define MLIBC_STAT_H
#include <abi-bits/stat.h>
/* Used by utimensat and friends */
#define UTIME_NOW ((1l << 30) - 1l)
#define UTIME_OMIT ((1l << 30) - 2l)
#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
/* POSIX compatibility macros */
#define st_atime st_atim.tv_sec
#define st_mtime st_mtim.tv_sec
#define st_ctime st_ctim.tv_sec
#endif /* MLIBC_STAT_H */
@@ -0,0 +1,6 @@
#ifndef _MLIBC_TIMER_T_H
#define _MLIBC_TIMER_T_H
typedef void * timer_t;
#endif /* _MLIBC_TIMER_T_H */
@@ -0,0 +1,12 @@
#ifndef MLIBC_TIMEVAL_H
#define MLIBC_TIMEVAL_H
#include <bits/ansi/time_t.h>
#include <abi-bits/suseconds_t.h>
struct timeval {
time_t tv_sec;
suseconds_t tv_usec;
};
#endif /* MLIBC_TIMEVAL_H */