diff options
author | Ian Moffett <ian@osmora.org> | 2024-03-07 17:28:00 -0500 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2024-03-07 17:28:32 -0500 |
commit | bd5969fc876a10b18613302db7087ef3c40f18e1 (patch) | |
tree | 7c2b8619afe902abf99570df2873fbdf40a4d1a1 /lib/mlibc/options/posix/include/bits | |
parent | a95b38b1b92b172e6cc4e8e56a88a30cc65907b0 (diff) |
lib: Add mlibc
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'lib/mlibc/options/posix/include/bits')
18 files changed, 552 insertions, 0 deletions
diff --git a/lib/mlibc/options/posix/include/bits/posix/fd_set.h b/lib/mlibc/options/posix/include/bits/posix/fd_set.h new file mode 100644 index 0000000..554738e --- /dev/null +++ b/lib/mlibc/options/posix/include/bits/posix/fd_set.h @@ -0,0 +1,14 @@ +#ifndef MLIBC_FD_SET_H +#define MLIBC_FD_SET_H + +#include <bits/types.h> + +typedef struct { + union { + __mlibc_uint8 __mlibc_elems[128]; + // Some programs require the fds_bits field to be present + __mlibc_uint8 fds_bits[128]; + }; +} fd_set; + +#endif // MLIBC_FD_SET_H diff --git a/lib/mlibc/options/posix/include/bits/posix/id_t.h b/lib/mlibc/options/posix/include/bits/posix/id_t.h new file mode 100644 index 0000000..f222bc1 --- /dev/null +++ b/lib/mlibc/options/posix/include/bits/posix/id_t.h @@ -0,0 +1,6 @@ +#ifndef _MLIBC_ID_T_H +#define _MLIBC_ID_T_H + +typedef unsigned int id_t; + +#endif // _MLIBC_ID_T_H diff --git a/lib/mlibc/options/posix/include/bits/posix/in_addr_t.h b/lib/mlibc/options/posix/include/bits/posix/in_addr_t.h new file mode 100644 index 0000000..bac9ff2 --- /dev/null +++ b/lib/mlibc/options/posix/include/bits/posix/in_addr_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 diff --git a/lib/mlibc/options/posix/include/bits/posix/in_port_t.h b/lib/mlibc/options/posix/include/bits/posix/in_port_t.h new file mode 100644 index 0000000..0368159 --- /dev/null +++ b/lib/mlibc/options/posix/include/bits/posix/in_port_t.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 diff --git a/lib/mlibc/options/posix/include/bits/posix/iovec.h b/lib/mlibc/options/posix/include/bits/posix/iovec.h new file mode 100644 index 0000000..c004f1c --- /dev/null +++ b/lib/mlibc/options/posix/include/bits/posix/iovec.h @@ -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 diff --git a/lib/mlibc/options/posix/include/bits/posix/locale_t.h b/lib/mlibc/options/posix/include/bits/posix/locale_t.h new file mode 100644 index 0000000..c128d58 --- /dev/null +++ b/lib/mlibc/options/posix/include/bits/posix/locale_t.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 diff --git a/lib/mlibc/options/posix/include/bits/posix/posix_ctype.h b/lib/mlibc/options/posix/include/bits/posix/posix_ctype.h new file mode 100644 index 0000000..2b11057 --- /dev/null +++ b/lib/mlibc/options/posix/include/bits/posix/posix_ctype.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 diff --git a/lib/mlibc/options/posix/include/bits/posix/posix_locale.h b/lib/mlibc/options/posix/include/bits/posix/posix_locale.h new file mode 100644 index 0000000..7554bc5 --- /dev/null +++ b/lib/mlibc/options/posix/include/bits/posix/posix_locale.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 diff --git a/lib/mlibc/options/posix/include/bits/posix/posix_signal.h b/lib/mlibc/options/posix/include/bits/posix/posix_signal.h new file mode 100644 index 0000000..20f030f --- /dev/null +++ b/lib/mlibc/options/posix/include/bits/posix/posix_signal.h @@ -0,0 +1,111 @@ + +#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 */ + +// 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; + +#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 *); +int sigprocmask(int, const sigset_t *__restrict, sigset_t *__restrict); + +int pthread_sigmask(int, const sigset_t *__restrict, sigset_t *__restrict); +int pthread_kill(pthread_t, int); + +// functions to handle signals +int sigaction(int, const struct sigaction *__restrict, struct sigaction *__restrict); +int sigpending(sigset_t *); + +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, int); +int killpg(int, int); + +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 + diff --git a/lib/mlibc/options/posix/include/bits/posix/posix_stdio.h b/lib/mlibc/options/posix/include/bits/posix/posix_stdio.h new file mode 100644 index 0000000..4572a04 --- /dev/null +++ b/lib/mlibc/options/posix/include/bits/posix/posix_stdio.h @@ -0,0 +1,72 @@ + +#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> + +// MISSING: var_list + +#ifdef __cplusplus +extern "C" { +#endif + +#define P_tmpdir "/tmp" + +#ifndef __MLIBC_ABI_ONLY + +typedef struct __mlibc_file_base FILE; + +int fileno(FILE *file); +FILE *fdopen(int fd, const char *mode); + +FILE *fmemopen(void *__restrict, size_t, const char *__restrict); +int pclose(FILE *); +FILE *popen(const char*, const char *); +FILE *open_memstream(char **, size_t *); + +int fseeko(FILE *stream, off_t offset, int whence); +off_t ftello(FILE *stream); + +int dprintf(int fd, const char *format, ...); +int vdprintf(int fd, const char *format, __builtin_va_list args); + +char *fgetln(FILE *, size_t *); + +#endif /* !__MLIBC_ABI_ONLY */ + +#define RENAME_EXCHANGE (1 << 1) + +// GNU extensions +typedef ssize_t (cookie_read_function_t)(void *, char *, size_t); +typedef ssize_t (cookie_write_function_t)(void *, const char *, size_t); +typedef int (cookie_seek_function_t)(void *, off_t *, int); +typedef int (cookie_close_function_t)(void *); + +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 */ + + diff --git a/lib/mlibc/options/posix/include/bits/posix/posix_stdlib.h b/lib/mlibc/options/posix/include/bits/posix/posix_stdlib.h new file mode 100644 index 0000000..5248fca --- /dev/null +++ b/lib/mlibc/options/posix/include/bits/posix/posix_stdlib.h @@ -0,0 +1,73 @@ + +#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); +void srand48(long int); +char *initstate(unsigned int, char *, size_t); +char *setstate(char *); +void srandom(unsigned int); + +// ---------------------------------------------------------------------------- +// Environment. +// ---------------------------------------------------------------------------- + +int putenv(char *); +int setenv(const char *, const char *, int); +int unsetenv(const char *); + +// ---------------------------------------------------------------------------- +// Path handling. +// ---------------------------------------------------------------------------- + +int mkstemp(char *); +int mkstemps(char *pattern, int suffixlen); +int mkostemp(char *, int flags); +int mkostemps(char *pattern, int suffixlen, int flags); +char *mkdtemp(char *path); + +char *realpath(const char *__restrict, char *__restrict); + +// ---------------------------------------------------------------------------- +// 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 getloadavg(double *, int); + +// GNU extension +char *secure_getenv(const char *); +char *canonicalize_file_name(const char *); + +// BSD extension +void *reallocarray(void *, size_t, size_t); + +int clearenv(void); + +#endif /* !__MLIBC_ABI_ONLY */ + +#ifdef __cplusplus +} +#endif + +#endif // MLIBC_POSIX_STDLIB_H + diff --git a/lib/mlibc/options/posix/include/bits/posix/posix_string.h b/lib/mlibc/options/posix/include/bits/posix/posix_string.h new file mode 100644 index 0000000..1f61942 --- /dev/null +++ b/lib/mlibc/options/posix/include/bits/posix/posix_string.h @@ -0,0 +1,57 @@ + +#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 *, size_t); +size_t strnlen(const char *, size_t); +char *strtok_r(char *__restrict, const char *__restrict, char **__restrict); +char *strsep(char **stringp, const char *delim); +char *strsignal(int sig); +char *stpcpy(char *__restrict, const char *__restrict); +char *stpncpy(char *__restrict, const char *__restrict, 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); + +// GNU extensions. +#if defined(_GNU_SOURCE) +char *strcasestr(const char *, const char *); +#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 *, int, size_t); +#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 + diff --git a/lib/mlibc/options/posix/include/bits/posix/posix_time.h b/lib/mlibc/options/posix/include/bits/posix/posix_time.h new file mode 100644 index 0000000..d3e8e1d --- /dev/null +++ b/lib/mlibc/options/posix/include/bits/posix/posix_time.h @@ -0,0 +1,25 @@ +#ifndef MLIBC_POSIX_TIME_H +#define MLIBC_POSIX_TIME_H + +#include <bits/posix/timeval.h> + +#define TIMER_ABSTIME 1 + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef __MLIBC_ABI_ONLY + +int utimes(const char *, const struct timeval[2]); + +// Not standardized, Linux and BSDs have it +int futimes(int, const struct timeval[2]); + +#endif /* !__MLIBC_ABI_ONLY */ + +#ifdef __cplusplus +} +#endif + +#endif // MLIBC_POSIX_TIME_H diff --git a/lib/mlibc/options/posix/include/bits/posix/posix_wctype.h b/lib/mlibc/options/posix/include/bits/posix/posix_wctype.h new file mode 100644 index 0000000..4d2887c --- /dev/null +++ b/lib/mlibc/options/posix/include/bits/posix/posix_wctype.h @@ -0,0 +1,44 @@ +#ifndef _POSIX_WCTYPE_H +#define _POSIX_WCTYPE_H + +#include <bits/posix/locale_t.h> +#include <bits/wint_t.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef __MLIBC_ABI_ONLY + +typedef unsigned long wctype_t; +typedef unsigned long wctrans_t; + +int iswalnum_l(wint_t, locale_t); +int iswblank_l(wint_t, locale_t); +int iswcntrl_l(wint_t, locale_t); +int iswdigit_l(wint_t, locale_t); +int iswgraph_l(wint_t, locale_t); +int iswlower_l(wint_t, locale_t); +int iswprint_l(wint_t, locale_t); +int iswpunct_l(wint_t, locale_t); +int iswspace_l(wint_t, locale_t); +int iswupper_l(wint_t, locale_t); +int iswxdigit_l(wint_t, locale_t); +int iswalpha_l(wint_t, locale_t); + +wctype_t wctype_l(const char *); +int iswctype_l(wint_t, wctype_t); + +wint_t towlower_l(wint_t, locale_t); +wint_t towupper_l(wint_t, locale_t); + +wctrans_t wctrans_l(const char *, locale_t); +wint_t towctrans_l(wint_t, wctrans_t, locale_t); + +#endif /* !__MLIBC_ABI_ONLY */ + +#ifdef __cplusplus +} +#endif + +#endif // _POSIX_WCTYPE_H diff --git a/lib/mlibc/options/posix/include/bits/posix/pthread_t.h b/lib/mlibc/options/posix/include/bits/posix/pthread_t.h new file mode 100644 index 0000000..1310c40 --- /dev/null +++ b/lib/mlibc/options/posix/include/bits/posix/pthread_t.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 diff --git a/lib/mlibc/options/posix/include/bits/posix/stat.h b/lib/mlibc/options/posix/include/bits/posix/stat.h new file mode 100644 index 0000000..4dd081d --- /dev/null +++ b/lib/mlibc/options/posix/include/bits/posix/stat.h @@ -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 + diff --git a/lib/mlibc/options/posix/include/bits/posix/timer_t.h b/lib/mlibc/options/posix/include/bits/posix/timer_t.h new file mode 100644 index 0000000..b230501 --- /dev/null +++ b/lib/mlibc/options/posix/include/bits/posix/timer_t.h @@ -0,0 +1,6 @@ +#ifndef _MLIBC_TIMER_T_H +#define _MLIBC_TIMER_T_H + +typedef void * timer_t; + +#endif // _MLIBC_TIMER_T_H diff --git a/lib/mlibc/options/posix/include/bits/posix/timeval.h b/lib/mlibc/options/posix/include/bits/posix/timeval.h new file mode 100644 index 0000000..445ee7f --- /dev/null +++ b/lib/mlibc/options/posix/include/bits/posix/timeval.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 |