internal: refactor sysdeps.hpp into option specific sysdeps
This commit is contained in:
parent
c688e95f4e
commit
e773a516ad
7
abis/linux/x86_64/blkcnt_t.h
Normal file
7
abis/linux/x86_64/blkcnt_t.h
Normal file
|
@ -0,0 +1,7 @@
|
|||
#ifndef _ABIBITS_BLKCNT_T_H
|
||||
#define _ABIBITS_BLKCNT_T_H
|
||||
|
||||
// TODO: use int64_t?
|
||||
typedef long blkcnt_t;
|
||||
|
||||
#endif // _ABIBITS_BLKCNT_T_H
|
9
abis/linux/x86_64/blksize_t.h
Normal file
9
abis/linux/x86_64/blksize_t.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
|
||||
#ifndef _ABIBITS_BLKSIZE_T_H
|
||||
#define _ABIBITS_BLKSIZE_T_H
|
||||
|
||||
// TODO: use int64_t?
|
||||
typedef long blksize_t;
|
||||
|
||||
#endif // _ABIBITS_BLKSIZE_T_H
|
||||
|
8
abis/linux/x86_64/dev_t.h
Normal file
8
abis/linux/x86_64/dev_t.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
|
||||
#ifndef _ABIBITS_DEV_T_H
|
||||
#define _ABIBITS_DEV_T_H
|
||||
|
||||
typedef unsigned long dev_t;
|
||||
|
||||
#endif // _ABIBITS_DEV_T_H
|
||||
|
8
abis/linux/x86_64/gid_t.h
Normal file
8
abis/linux/x86_64/gid_t.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
|
||||
#ifndef _ABIBITS_GID_T_H
|
||||
#define _ABIBITS_GID_T_H
|
||||
|
||||
typedef int gid_t;
|
||||
|
||||
#endif // _ABIBITS_GID_T_H
|
||||
|
9
abis/linux/x86_64/ino_t.h
Normal file
9
abis/linux/x86_64/ino_t.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
|
||||
#ifndef _ABIBITS_INO_T_H
|
||||
#define _ABIBITS_INO_T_H
|
||||
|
||||
// TODO: use (u)int64_t?
|
||||
typedef long ino_t;
|
||||
|
||||
#endif // _ABIBITS_INO_T_H
|
||||
|
8
abis/linux/x86_64/mode_t.h
Normal file
8
abis/linux/x86_64/mode_t.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
|
||||
#ifndef _ABIBITS_MODE_T_H
|
||||
#define _ABIBITS_MODE_T_H
|
||||
|
||||
typedef int mode_t;
|
||||
|
||||
#endif // _ABIBITS_MODE_T_H
|
||||
|
8
abis/linux/x86_64/nlink_t.h
Normal file
8
abis/linux/x86_64/nlink_t.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
|
||||
#ifndef _ABIBITS_NLINK_T_H
|
||||
#define _ABIBITS_NLINK_T_H
|
||||
|
||||
typedef int nlink_t;
|
||||
|
||||
#endif // _ABIBITS_NLINK_T_H
|
||||
|
8
abis/linux/x86_64/pid_t.h
Normal file
8
abis/linux/x86_64/pid_t.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
|
||||
#ifndef _ABIBITS_PID_T_H
|
||||
#define _ABIBITS_PID_T_H
|
||||
|
||||
typedef int pid_t;
|
||||
|
||||
#endif // _ABIBITS_PID_T_H
|
||||
|
|
@ -2,11 +2,8 @@
|
|||
#define _ABIBITS_SIGNAL_H
|
||||
|
||||
#include <bits/feature.h>
|
||||
|
||||
#ifdef __MLIBC_POSIX_OPTION
|
||||
|
||||
#include <bits/posix/pid_t.h>
|
||||
#include <bits/posix/uid_t.h>
|
||||
#include <abi-bits/pid_t.h>
|
||||
#include <abi-bits/uid_t.h>
|
||||
|
||||
union sigval {
|
||||
int sival_int;
|
||||
|
@ -24,8 +21,6 @@ typedef struct {
|
|||
union sigval si_value;
|
||||
} siginfo_t;
|
||||
|
||||
#endif // __MLIBC_POSIX_OPTION
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -46,7 +41,10 @@ extern "C" {
|
|||
#define SIGRTMIN 35
|
||||
#define SIGRTMAX 64
|
||||
|
||||
#ifdef __MLIBC_POSIX_OPTION
|
||||
// TODO: replace this by uint64_t
|
||||
typedef long sigset_t;
|
||||
|
||||
#if __MLIBC_POSIX_OPTION
|
||||
|
||||
#define SIGHUP 1
|
||||
#define SIGQUIT 3
|
||||
|
@ -97,9 +95,6 @@ extern "C" {
|
|||
|
||||
#define NSIG 65
|
||||
|
||||
// TODO: replace this by uint64_t
|
||||
typedef long sigset_t;
|
||||
|
||||
struct sigevent {
|
||||
union sigval sigev_value;
|
||||
int sigev_notify;
|
||||
|
@ -108,6 +103,8 @@ struct sigevent {
|
|||
// MISSING: sigev_notify_attributes
|
||||
};
|
||||
|
||||
#endif // __MLIBC_POSIX_OPTION
|
||||
|
||||
struct sigaction {
|
||||
union {
|
||||
void (*sa_handler)(int);
|
||||
|
@ -120,8 +117,6 @@ struct sigaction {
|
|||
#define sa_handler __sa_handler.sa_handler
|
||||
#define sa_sigaction __sa_handler.sa_sigaction
|
||||
|
||||
#endif // __MLIBC_POSIX_OPTION
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
#ifndef _ABIBITS_STAT_H
|
||||
#define _ABIBITS_STAT_H
|
||||
|
||||
#include <bits/posix/uid_t.h>
|
||||
#include <bits/posix/gid_t.h>
|
||||
#include <bits/posix/off_t.h>
|
||||
#include <bits/posix/mode_t.h>
|
||||
#include <bits/posix/dev_t.h>
|
||||
#include <bits/posix/ino_t.h>
|
||||
#include <bits/posix/blksize_t.h>
|
||||
#include <bits/posix/blkcnt_t.h>
|
||||
#include <bits/posix/nlink_t.h>
|
||||
#include <abi-bits/uid_t.h>
|
||||
#include <abi-bits/gid_t.h>
|
||||
#include <bits/off_t.h>
|
||||
#include <abi-bits/mode_t.h>
|
||||
#include <abi-bits/dev_t.h>
|
||||
#include <abi-bits/ino_t.h>
|
||||
#include <abi-bits/blksize_t.h>
|
||||
#include <abi-bits/blkcnt_t.h>
|
||||
#include <abi-bits/nlink_t.h>
|
||||
#include <bits/ansi/time_t.h>
|
||||
#include <bits/ansi/timespec.h>
|
||||
|
||||
|
|
8
abis/linux/x86_64/uid_t.h
Normal file
8
abis/linux/x86_64/uid_t.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
|
||||
#ifndef _ABIBITS_UID_T_H
|
||||
#define _ABIBITS_UID_T_H
|
||||
|
||||
typedef int uid_t;
|
||||
|
||||
#endif // _ABIBITS_UID_T_H
|
||||
|
7
abis/mlibc/blkcnt_t.h
Normal file
7
abis/mlibc/blkcnt_t.h
Normal file
|
@ -0,0 +1,7 @@
|
|||
#ifndef _ABIBITS_BLKCNT_T_H
|
||||
#define _ABIBITS_BLKCNT_T_H
|
||||
|
||||
// TODO: use int64_t?
|
||||
typedef long blkcnt_t;
|
||||
|
||||
#endif // _ABIBITS_BLKCNT_T_H
|
9
abis/mlibc/blksize_t.h
Normal file
9
abis/mlibc/blksize_t.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
|
||||
#ifndef _ABIBITS_BLKSIZE_T_H
|
||||
#define _ABIBITS_BLKSIZE_T_H
|
||||
|
||||
// TODO: use int64_t?
|
||||
typedef long blksize_t;
|
||||
|
||||
#endif // _ABIBITS_BLKSIZE_T_H
|
||||
|
8
abis/mlibc/dev_t.h
Normal file
8
abis/mlibc/dev_t.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
|
||||
#ifndef _ABIBITS_DEV_T_H
|
||||
#define _ABIBITS_DEV_T_H
|
||||
|
||||
typedef unsigned long dev_t;
|
||||
|
||||
#endif // _ABIBITS_DEV_T_H
|
||||
|
8
abis/mlibc/gid_t.h
Normal file
8
abis/mlibc/gid_t.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
|
||||
#ifndef _ABIBITS_GID_T_H
|
||||
#define _ABIBITS_GID_T_H
|
||||
|
||||
typedef int gid_t;
|
||||
|
||||
#endif // _ABIBITS_GID_T_H
|
||||
|
9
abis/mlibc/ino_t.h
Normal file
9
abis/mlibc/ino_t.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
|
||||
#ifndef _ABIBITS_INO_T_H
|
||||
#define _ABIBITS_INO_T_H
|
||||
|
||||
// TODO: use (u)int64_t?
|
||||
typedef long ino_t;
|
||||
|
||||
#endif // _ABIBITS_INO_T_H
|
||||
|
8
abis/mlibc/mode_t.h
Normal file
8
abis/mlibc/mode_t.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
|
||||
#ifndef _ABIBITS_MODE_T_H
|
||||
#define _ABIBITS_MODE_T_H
|
||||
|
||||
typedef int mode_t;
|
||||
|
||||
#endif // _ABIBITS_MODE_T_H
|
||||
|
8
abis/mlibc/nlink_t.h
Normal file
8
abis/mlibc/nlink_t.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
|
||||
#ifndef _ABIBITS_NLINK_T_H
|
||||
#define _ABIBITS_NLINK_T_H
|
||||
|
||||
typedef int nlink_t;
|
||||
|
||||
#endif // _ABIBITS_NLINK_T_H
|
||||
|
8
abis/mlibc/pid_t.h
Normal file
8
abis/mlibc/pid_t.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
|
||||
#ifndef _ABIBITS_PID_T_H
|
||||
#define _ABIBITS_PID_T_H
|
||||
|
||||
typedef int pid_t;
|
||||
|
||||
#endif // _ABIBITS_PID_T_H
|
||||
|
|
@ -3,10 +3,8 @@
|
|||
|
||||
#include <bits/feature.h>
|
||||
|
||||
#ifdef __MLIBC_POSIX_OPTION
|
||||
|
||||
#include <bits/posix/pid_t.h>
|
||||
#include <bits/posix/uid_t.h>
|
||||
#include <abi-bits/pid_t.h>
|
||||
#include <abi-bits/uid_t.h>
|
||||
|
||||
union sigval {
|
||||
int sival_int;
|
||||
|
@ -24,8 +22,6 @@ typedef struct {
|
|||
union sigval si_value;
|
||||
} siginfo_t;
|
||||
|
||||
#endif // __MLIBC_POSIX_OPTION
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -46,6 +42,9 @@ extern "C" {
|
|||
#define SIGRTMIN 11
|
||||
#define SIGRTMAX 12
|
||||
|
||||
// TODO: replace this by uint64_t
|
||||
typedef long sigset_t;
|
||||
|
||||
#ifdef __MLIBC_POSIX_OPTION
|
||||
|
||||
#define SIGALRM 8
|
||||
|
@ -95,9 +94,6 @@ extern "C" {
|
|||
|
||||
#define NSIG 65
|
||||
|
||||
// TODO: replace this by uint64_t
|
||||
typedef long sigset_t;
|
||||
|
||||
struct sigevent {
|
||||
int sigev_notify;
|
||||
int sigev_signo;
|
||||
|
@ -106,6 +102,8 @@ struct sigevent {
|
|||
// MISSING: sigev_notify_attributes
|
||||
};
|
||||
|
||||
#endif // __MLIBC_POSIX_OPTION
|
||||
|
||||
struct sigaction {
|
||||
void (*sa_handler)(int);
|
||||
sigset_t sa_mask;
|
||||
|
@ -113,8 +111,6 @@ struct sigaction {
|
|||
void (*sa_sigaction)(int, siginfo_t *, void *);
|
||||
};
|
||||
|
||||
#endif // __MLIBC_POSIX_OPTION
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
#ifndef _ABIBITS_STAT_H
|
||||
#define _ABIBITS_STAT_H
|
||||
|
||||
#include <bits/posix/uid_t.h>
|
||||
#include <bits/posix/gid_t.h>
|
||||
#include <bits/posix/off_t.h>
|
||||
#include <bits/posix/mode_t.h>
|
||||
#include <bits/posix/dev_t.h>
|
||||
#include <bits/posix/ino_t.h>
|
||||
#include <bits/posix/blksize_t.h>
|
||||
#include <bits/posix/blkcnt_t.h>
|
||||
#include <bits/posix/nlink_t.h>
|
||||
#include <abi-bits/uid_t.h>
|
||||
#include <abi-bits/gid_t.h>
|
||||
#include <bits/off_t.h>
|
||||
#include <abi-bits/mode_t.h>
|
||||
#include <abi-bits/dev_t.h>
|
||||
#include <abi-bits/ino_t.h>
|
||||
#include <abi-bits/blksize_t.h>
|
||||
#include <abi-bits/blkcnt_t.h>
|
||||
#include <abi-bits/nlink_t.h>
|
||||
#include <bits/ansi/time_t.h>
|
||||
#include <bits/ansi/timespec.h>
|
||||
|
||||
|
|
8
abis/mlibc/uid_t.h
Normal file
8
abis/mlibc/uid_t.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
|
||||
#ifndef _ABIBITS_UID_T_H
|
||||
#define _ABIBITS_UID_T_H
|
||||
|
||||
typedef int uid_t;
|
||||
|
||||
#endif // _ABIBITS_UID_T_H
|
||||
|
|
@ -4,6 +4,7 @@ fs = import('fs')
|
|||
|
||||
rtdl_include_dirs = [
|
||||
include_directories('options/internal/include'),
|
||||
include_directories('options/rtdl/include'),
|
||||
]
|
||||
libc_include_dirs = [
|
||||
include_directories('options/internal/include'),
|
||||
|
@ -169,6 +170,8 @@ if not no_headers
|
|||
'options/internal/include/bits/machine.h',
|
||||
'options/internal/include/bits/mbstate.h',
|
||||
'options/internal/include/bits/null.h',
|
||||
'options/internal/include/bits/off_t.h',
|
||||
'options/internal/include/bits/ssize_t.h',
|
||||
subdir: 'bits'
|
||||
)
|
||||
endif
|
||||
|
|
|
@ -106,7 +106,9 @@ char *getenv(const char *name) {
|
|||
return const_cast<char *>(view.data() + s + 1);
|
||||
}
|
||||
|
||||
int putenv(const char *string) {
|
||||
namespace mlibc {
|
||||
|
||||
int putenv(char *string) {
|
||||
frg::string_view view{string};
|
||||
size_t s = view.find_first('=');
|
||||
if(s == size_t(-1))
|
||||
|
@ -116,6 +118,10 @@ int putenv(const char *string) {
|
|||
assign_variable(view.sub_string(0, s), string, true);
|
||||
return 0;
|
||||
}
|
||||
} // namespace mlibc
|
||||
int putenv(char *string) {
|
||||
return mlibc::putenv(string);
|
||||
}
|
||||
|
||||
int setenv(const char *name, const char *value, int overwrite) {
|
||||
frg::string_view view{name};
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include <frg/mutex.hpp>
|
||||
#include <mlibc/allocator.hpp>
|
||||
#include <mlibc/file-io.hpp>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/ansi-sysdeps.hpp>
|
||||
#include <mlibc/lock.hpp>
|
||||
|
||||
namespace mlibc {
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <string.h>
|
||||
|
||||
#include <bits/ensure.h>
|
||||
#include <bits/feature.h>
|
||||
|
||||
#include <mlibc/debug.hpp>
|
||||
#include <frg/optional.hpp>
|
||||
|
@ -103,7 +104,7 @@ char *setlocale(int category, const char *locale) {
|
|||
__ensure(!strcmp(current_desc.locale, __mlibc_timeDesc.locale));
|
||||
if(!locale)
|
||||
return const_cast<char *>(current_desc.locale);
|
||||
|
||||
|
||||
frg::optional<__Mlibc_LocaleDesc> new_desc = __mlibc_queryLocale(locale);
|
||||
if(!new_desc)
|
||||
return nullptr;
|
||||
|
@ -118,7 +119,7 @@ char *setlocale(int category, const char *locale) {
|
|||
__Mlibc_LocaleDesc current_desc = __mlibc_currentLocale(category);
|
||||
if(!locale)
|
||||
return const_cast<char *>(current_desc.locale);
|
||||
|
||||
|
||||
frg::optional<__Mlibc_LocaleDesc> new_desc = __mlibc_queryLocale(locale);
|
||||
if(!new_desc)
|
||||
return nullptr;
|
||||
|
@ -129,14 +130,3 @@ char *setlocale(int category, const char *locale) {
|
|||
struct lconv *localeconv(void) {
|
||||
return &c_locale_lconv;
|
||||
}
|
||||
|
||||
locale_t newlocale(int category_mask, const char *locale, locale_t base) {
|
||||
__ensure(!"Not implemented");
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void freelocale(locale_t locobj) {
|
||||
__ensure(!"Not implemented");
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <signal.h>
|
||||
|
||||
#include <mlibc/debug.hpp>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/ansi-sysdeps.hpp>
|
||||
|
||||
__sighandler signal(int sn, __sighandler handler) {
|
||||
if(!mlibc::sys_sigaction) {
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#include <stdlib.h>
|
||||
#include <wchar.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <bits/ensure.h>
|
||||
|
@ -16,7 +15,7 @@
|
|||
#include <mlibc/allocator.hpp>
|
||||
#include <mlibc/debug.hpp>
|
||||
#include <mlibc/file-io.hpp>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/ansi-sysdeps.hpp>
|
||||
#include <frg/mutex.hpp>
|
||||
|
||||
template<typename F>
|
||||
|
@ -187,13 +186,30 @@ struct ResizePrinter {
|
|||
};
|
||||
|
||||
int remove(const char *filename) {
|
||||
struct stat statbuf;
|
||||
if(stat(filename, &statbuf) != 0)
|
||||
if(!mlibc::sys_rmdir) {
|
||||
MLIBC_MISSING_SYSDEP();
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
if(S_ISDIR(statbuf.st_mode))
|
||||
return rmdir(filename);
|
||||
else
|
||||
return unlink(filename);
|
||||
}
|
||||
|
||||
if(int e = mlibc::sys_rmdir(filename); e) {
|
||||
if (e == ENOTDIR) {
|
||||
if(!mlibc::sys_unlink) {
|
||||
MLIBC_MISSING_SYSDEP();
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
if(e = mlibc::sys_unlink(filename); e) {
|
||||
errno = e;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rename(const char *path, const char *new_path) {
|
||||
|
@ -268,14 +284,6 @@ int printf(const char *__restrict format, ...) {
|
|||
return result;
|
||||
}
|
||||
|
||||
int dprintf(int fd, const char *format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
int result = vdprintf(fd, format, args);
|
||||
va_end(args);
|
||||
return result;
|
||||
}
|
||||
|
||||
namespace {
|
||||
enum {
|
||||
SCANF_TYPE_CHAR,
|
||||
|
@ -763,13 +771,6 @@ int vsscanf(const char *__restrict buffer, const char *__restrict format, __gnuc
|
|||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
int vdprintf(int fd, const char *format, __gnuc_va_list args) {
|
||||
FILE *file = fdopen(fd, "a");
|
||||
int ret = vfprintf(file, format, args);
|
||||
fclose(file);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int fwprintf(FILE *__restrict, const wchar_t *__restrict, ...) MLIBC_STUB_BODY
|
||||
int fwscanf(FILE *__restrict, const wchar_t *__restrict, ...) MLIBC_STUB_BODY
|
||||
int vfwprintf(FILE *__restrict, const wchar_t *__restrict, __gnuc_va_list) MLIBC_STUB_BODY
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
#include <mlibc/allocator.hpp>
|
||||
#include <mlibc/charcode.hpp>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/ansi-sysdeps.hpp>
|
||||
#include <mlibc/strtofp.hpp>
|
||||
|
||||
extern "C" int __cxa_atexit(void (*function)(void *), void *argument, void *dso_tag);
|
||||
|
@ -418,9 +418,3 @@ int posix_memalign(void **out, size_t align, size_t size) {
|
|||
*out = p;
|
||||
return 0;
|
||||
}
|
||||
|
||||
double strtod_l(const char *__restrict__ nptr, char ** __restrict__ endptr, locale_t loc) {
|
||||
__ensure(!"Not implemented");
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
|
||||
#include <errno.h>
|
||||
#include <byteswap.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
#include <wchar.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -13,9 +9,10 @@
|
|||
#include <bits/ensure.h>
|
||||
#include <mlibc/debug.hpp>
|
||||
#include <mlibc/file-window.hpp>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/ansi-sysdeps.hpp>
|
||||
#include <mlibc/allocator.hpp>
|
||||
#include <mlibc/lock.hpp>
|
||||
#include <mlibc/bitutil.hpp>
|
||||
|
||||
#include <frg/mutex.hpp>
|
||||
|
||||
|
@ -240,12 +237,12 @@ void tzset(void) {
|
|||
// TODO(geert): we can probably cache this somehow
|
||||
tzfile tzfile_time;
|
||||
memcpy(&tzfile_time, reinterpret_cast<char *>(get_localtime_window()->get()), sizeof(tzfile));
|
||||
tzfile_time.tzh_ttisgmtcnt = bswap_32(tzfile_time.tzh_ttisgmtcnt);
|
||||
tzfile_time.tzh_ttisstdcnt = bswap_32(tzfile_time.tzh_ttisstdcnt);
|
||||
tzfile_time.tzh_leapcnt = bswap_32(tzfile_time.tzh_leapcnt);
|
||||
tzfile_time.tzh_timecnt = bswap_32(tzfile_time.tzh_timecnt);
|
||||
tzfile_time.tzh_typecnt = bswap_32(tzfile_time.tzh_typecnt);
|
||||
tzfile_time.tzh_charcnt = bswap_32(tzfile_time.tzh_charcnt);
|
||||
tzfile_time.tzh_ttisgmtcnt = mlibc::bit_util<uint32_t>::byteswap(tzfile_time.tzh_ttisgmtcnt);
|
||||
tzfile_time.tzh_ttisstdcnt = mlibc::bit_util<uint32_t>::byteswap(tzfile_time.tzh_ttisstdcnt);
|
||||
tzfile_time.tzh_leapcnt = mlibc::bit_util<uint32_t>::byteswap(tzfile_time.tzh_leapcnt);
|
||||
tzfile_time.tzh_timecnt = mlibc::bit_util<uint32_t>::byteswap(tzfile_time.tzh_timecnt);
|
||||
tzfile_time.tzh_typecnt = mlibc::bit_util<uint32_t>::byteswap(tzfile_time.tzh_typecnt);
|
||||
tzfile_time.tzh_charcnt = mlibc::bit_util<uint32_t>::byteswap(tzfile_time.tzh_charcnt);
|
||||
|
||||
if(tzfile_time.magic[0] != 'T' || tzfile_time.magic[1] != 'Z' || tzfile_time.magic[2] != 'i'
|
||||
|| tzfile_time.magic[3] != 'f') {
|
||||
|
@ -274,7 +271,7 @@ void tzset(void) {
|
|||
+ tzfile_time.tzh_timecnt * sizeof(int32_t)
|
||||
+ tzfile_time.tzh_timecnt * sizeof(uint8_t)
|
||||
+ i * sizeof(ttinfo), sizeof(ttinfo));
|
||||
time_info.tt_gmtoff = bswap_32(time_info.tt_gmtoff);
|
||||
time_info.tt_gmtoff = mlibc::bit_util<uint32_t>::byteswap(time_info.tt_gmtoff);
|
||||
if (!time_info.tt_isdst && !tzname[0]) {
|
||||
tzname[0] = abbrevs + time_info.tt_abbrind;
|
||||
timezone = -time_info.tt_gmtoff;
|
||||
|
@ -334,33 +331,6 @@ int clock_settime(clockid_t, const struct timespec *) {
|
|||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
int utimes(const char *filename, const struct timeval times[2]) {
|
||||
if (!mlibc::sys_utimensat) {
|
||||
MLIBC_MISSING_SYSDEP();
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
struct timespec time[2];
|
||||
if(times == nullptr) {
|
||||
time[0].tv_sec = UTIME_NOW;
|
||||
time[0].tv_nsec = UTIME_NOW;
|
||||
time[1].tv_sec = UTIME_NOW;
|
||||
time[1].tv_nsec = UTIME_NOW;
|
||||
} else {
|
||||
time[0].tv_sec = times[0].tv_sec;
|
||||
time[0].tv_nsec = times[0].tv_usec * 1000;
|
||||
time[1].tv_sec = times[1].tv_sec;
|
||||
time[1].tv_nsec = times[1].tv_usec * 1000;
|
||||
}
|
||||
|
||||
if (int e = mlibc::sys_utimensat(AT_FDCWD, filename, time, 0); e) {
|
||||
errno = e;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
time_t time(time_t *out) {
|
||||
time_t secs;
|
||||
long nanos;
|
||||
|
@ -412,12 +382,12 @@ void yearday_from_date(unsigned int year, unsigned int month, unsigned int day,
|
|||
int unix_local_from_gmt(time_t unix_gmt, time_t *offset, bool *dst, char **tm_zone) {
|
||||
tzfile tzfile_time;
|
||||
memcpy(&tzfile_time, reinterpret_cast<char *>(get_localtime_window()->get()), sizeof(tzfile));
|
||||
tzfile_time.tzh_ttisgmtcnt = bswap_32(tzfile_time.tzh_ttisgmtcnt);
|
||||
tzfile_time.tzh_ttisstdcnt = bswap_32(tzfile_time.tzh_ttisstdcnt);
|
||||
tzfile_time.tzh_leapcnt = bswap_32(tzfile_time.tzh_leapcnt);
|
||||
tzfile_time.tzh_timecnt = bswap_32(tzfile_time.tzh_timecnt);
|
||||
tzfile_time.tzh_typecnt = bswap_32(tzfile_time.tzh_typecnt);
|
||||
tzfile_time.tzh_charcnt = bswap_32(tzfile_time.tzh_charcnt);
|
||||
tzfile_time.tzh_ttisgmtcnt = mlibc::bit_util<uint32_t>::byteswap(tzfile_time.tzh_ttisgmtcnt);
|
||||
tzfile_time.tzh_ttisstdcnt = mlibc::bit_util<uint32_t>::byteswap(tzfile_time.tzh_ttisstdcnt);
|
||||
tzfile_time.tzh_leapcnt = mlibc::bit_util<uint32_t>::byteswap(tzfile_time.tzh_leapcnt);
|
||||
tzfile_time.tzh_timecnt = mlibc::bit_util<uint32_t>::byteswap(tzfile_time.tzh_timecnt);
|
||||
tzfile_time.tzh_typecnt = mlibc::bit_util<uint32_t>::byteswap(tzfile_time.tzh_typecnt);
|
||||
tzfile_time.tzh_charcnt = mlibc::bit_util<uint32_t>::byteswap(tzfile_time.tzh_charcnt);
|
||||
|
||||
if(tzfile_time.magic[0] != 'T' || tzfile_time.magic[1] != 'Z' || tzfile_time.magic[2] != 'i'
|
||||
|| tzfile_time.magic[3] != 'f') {
|
||||
|
@ -436,7 +406,7 @@ int unix_local_from_gmt(time_t unix_gmt, time_t *offset, bool *dst, char **tm_zo
|
|||
int32_t ttime;
|
||||
memcpy(&ttime, reinterpret_cast<char *>(get_localtime_window()->get()) + sizeof(tzfile)
|
||||
+ i * sizeof(int32_t), sizeof(int32_t));
|
||||
ttime = bswap_32(ttime);
|
||||
ttime = mlibc::bit_util<uint32_t>::byteswap(ttime);
|
||||
// If we are before the first transition, the format dicates that
|
||||
// the first ttinfo entry should be used (and not the ttinfo entry pointed
|
||||
// to by the first transition time).
|
||||
|
@ -464,7 +434,7 @@ int unix_local_from_gmt(time_t unix_gmt, time_t *offset, bool *dst, char **tm_zo
|
|||
+ tzfile_time.tzh_timecnt * sizeof(int32_t)
|
||||
+ tzfile_time.tzh_timecnt * sizeof(uint8_t)
|
||||
+ ttinfo_index * sizeof(ttinfo), sizeof(ttinfo));
|
||||
time_info.tt_gmtoff = bswap_32(time_info.tt_gmtoff);
|
||||
time_info.tt_gmtoff = mlibc::bit_util<uint32_t>::byteswap(time_info.tt_gmtoff);
|
||||
|
||||
char *abbrevs = reinterpret_cast<char *>(get_localtime_window()->get()) + sizeof(tzfile)
|
||||
+ tzfile_time.tzh_timecnt * sizeof(int32_t)
|
||||
|
|
|
@ -2,8 +2,9 @@
|
|||
#ifndef _LOCALE_H
|
||||
#define _LOCALE_H
|
||||
|
||||
#include <bits/feature.h>
|
||||
|
||||
#include <bits/null.h>
|
||||
#include <bits/posix/locale_t.h>
|
||||
|
||||
#define LC_ALL 1
|
||||
#define LC_COLLATE 2
|
||||
|
@ -61,8 +62,9 @@ struct lconv *localeconv(void);
|
|||
|
||||
// posix extension
|
||||
|
||||
locale_t newlocale(int category_mask, const char *locale, locale_t base);
|
||||
void freelocale(locale_t locobj);
|
||||
#if __MLIBC_POSIX_OPTION
|
||||
# include <bits/posix/posix_locale.h>
|
||||
#endif // __MLIBC_POSIX_OPTION
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
51
options/ansi/include/mlibc/ansi-sysdeps.hpp
Normal file
51
options/ansi/include/mlibc/ansi-sysdeps.hpp
Normal file
|
@ -0,0 +1,51 @@
|
|||
#ifndef MLIBC_ANSI_SYSDEPS
|
||||
#define MLIBC_ANSI_SYSDEPS
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <abi-bits/seek-whence.h>
|
||||
#include <abi-bits/vm-flags.h>
|
||||
#include <bits/off_t.h>
|
||||
#include <bits/ssize_t.h>
|
||||
#include <bits/ansi/time_t.h>
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
namespace mlibc [[gnu::visibility("hidden")]] {
|
||||
|
||||
[[noreturn]] void sys_exit(int status);
|
||||
[[noreturn, gnu::weak]] void sys_thread_exit();
|
||||
|
||||
int sys_open(const char *pathname, int flags, int *fd);
|
||||
[[gnu::weak]] int sys_flock(int fd, int options);
|
||||
|
||||
[[gnu::weak]] int sys_open_dir(const char *path, int *handle);
|
||||
[[gnu::weak]] int sys_read_entries(int handle, void *buffer, size_t max_size,
|
||||
size_t *bytes_read);
|
||||
|
||||
int sys_read(int fd, void *buf, size_t count, ssize_t *bytes_read);
|
||||
|
||||
int sys_write(int fd, const void *buf, size_t count, ssize_t *bytes_written);
|
||||
[[gnu::weak]] int sys_pread(int fd, void *buf, size_t n, off_t off, ssize_t *bytes_read);
|
||||
|
||||
int sys_seek(int fd, off_t offset, int whence, off_t *new_offset);
|
||||
int sys_close(int fd);
|
||||
|
||||
int sys_clock_get(int clock, time_t *secs, long *nanos);
|
||||
[[gnu::weak]] int sys_sleep(time_t *secs, long *nanos);
|
||||
// In contrast to the isatty() library function, the sysdep function uses return value
|
||||
// zero (and not one) to indicate that the file is a terminal.
|
||||
[[gnu::weak]] int sys_isatty(int fd);
|
||||
[[gnu::weak]] int sys_rmdir(const char *path);
|
||||
[[gnu::weak]] int sys_unlink(const char *path);
|
||||
[[gnu::weak]] int sys_rename(const char *path, const char *new_path);
|
||||
[[gnu::weak]] int sys_renameat(int olddirfd, const char *old_path, int newdirfd, const char *new_path);
|
||||
|
||||
[[gnu::weak]] int sys_sigprocmask(int how, const sigset_t *__restrict set,
|
||||
sigset_t *__restrict retrieve);
|
||||
[[gnu::weak]] int sys_sigaction(int, const struct sigaction *__restrict,
|
||||
struct sigaction *__restrict);
|
||||
|
||||
} //namespace mlibc
|
||||
|
||||
#endif // MLIBC_ANSI_SYSDEPS
|
10
options/ansi/include/mlibc/environment.hpp
Normal file
10
options/ansi/include/mlibc/environment.hpp
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifndef MLIBC_ENVIRONMENT_HPP
|
||||
#define MLIBC_ENVIRONMENT_HPP
|
||||
|
||||
namespace mlibc {
|
||||
|
||||
int putenv(char *string);
|
||||
|
||||
} // namespace mlibc
|
||||
|
||||
#endif // MLIBC_ENVIRONMENT_HPP
|
|
@ -8,7 +8,7 @@
|
|||
#include <bits/size_t.h>
|
||||
|
||||
// Glibc extensions require ssize_t.
|
||||
#include <bits/posix/ssize_t.h>
|
||||
#include <bits/ssize_t.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -27,7 +27,7 @@ extern "C" {
|
|||
struct __mlibc_file_base {
|
||||
// Buffer for I/O operations.
|
||||
char *__buffer_ptr;
|
||||
|
||||
|
||||
// Number of bytes the buffer can hold.
|
||||
size_t __buffer_size;
|
||||
|
||||
|
@ -111,7 +111,6 @@ int vsnprintf(char *__restrict buffer, size_t max_size,
|
|||
const char *__restrict format, __gnuc_va_list args);
|
||||
int vsprintf(char *__restrict buffer, const char *__restrict format, __gnuc_va_list args);
|
||||
int vsscanf(const char *__restrict buffer, const char *__restrict format, __gnuc_va_list args);
|
||||
int vdprintf(int fd, const char *format, __gnuc_va_list args);
|
||||
|
||||
// this is a gnu extension
|
||||
int vasprintf(char **, const char *, __gnuc_va_list);
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
#include <bits/null.h>
|
||||
#include <bits/size_t.h>
|
||||
#include <bits/wchar_t.h>
|
||||
#include <bits/posix/locale_t.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -106,10 +105,6 @@ int wctomb(char *mb_chr, wchar_t wc);
|
|||
size_t mbstowcs(wchar_t *__restrict wc_string, const char *__restrict mb_string, size_t max_size);
|
||||
size_t wcstombs(char *mb_string, const wchar_t *__restrict wc_string, size_t max_size);
|
||||
|
||||
// posix extension
|
||||
|
||||
double strtod_l(const char *__restrict__ nptr, char ** __restrict__ endptr, locale_t loc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -73,9 +73,11 @@ void tzset(void);
|
|||
|
||||
// POSIX extensions.
|
||||
|
||||
#if __MLIBC_POSIX_OPTION
|
||||
# include <bits/posix/posix_time.h>
|
||||
#endif // __MLIBC_POSIX_OPTION
|
||||
|
||||
#include <bits/ansi/clockid_t.h>
|
||||
#include <bits/posix/suseconds_t.h>
|
||||
#include <bits/posix/timeval.h>
|
||||
|
||||
#define TIMER_ABSTIME 1
|
||||
|
||||
|
@ -94,8 +96,6 @@ int clock_gettime(clockid_t, struct timespec *);
|
|||
int clock_nanosleep(clockid_t, int, const struct timespec *, struct timespec *);
|
||||
int clock_settime(clockid_t, const struct timespec *);
|
||||
|
||||
int utimes(const char *, const struct timeval[2]);
|
||||
|
||||
struct tm *localtime_r(const time_t *, struct tm *);
|
||||
|
||||
char *strptime(const char *__restrict, const char *__restrict,
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <bits/ensure.h>
|
||||
#include <mlibc/elf/startup.h>
|
||||
#include <mlibc/environment.hpp>
|
||||
|
||||
extern "C" size_t __init_array_start[];
|
||||
extern "C" size_t __init_array_end[];
|
||||
|
@ -60,7 +61,7 @@ void set_startup_data(int argc, char **argv, char **envp) {
|
|||
// TODO: Copy the arguments instead of pointing to them?
|
||||
auto ev = envp;
|
||||
while(*ev) {
|
||||
auto fail = putenv(*ev);
|
||||
auto fail = mlibc::putenv(*ev);
|
||||
__ensure(!fail);
|
||||
ev++;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include <bits/ensure.h>
|
||||
#include <mlibc/debug.hpp>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/glibc-sysdeps.hpp>
|
||||
|
||||
int ioctl(int fd, unsigned long request, ...) {
|
||||
va_list args;
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
#ifndef _GETOPT_H
|
||||
#define _GETOPT_H
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
|
10
options/glibc/include/mlibc/glibc-sysdeps.hpp
Normal file
10
options/glibc/include/mlibc/glibc-sysdeps.hpp
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifndef MLIBC_GLIBC_SYSDEPS
|
||||
#define MLIBC_GLIBC_SYSDEPS
|
||||
|
||||
namespace mlibc [[gnu::visibility("hidden")]] {
|
||||
|
||||
[[gnu::weak]] int sys_ioctl(int fd, unsigned long request, void *arg, int *result);
|
||||
|
||||
} // namespace mlibc
|
||||
|
||||
#endif // MLIBC_GLIBC_SYSDEPS
|
|
@ -1,8 +1,6 @@
|
|||
#ifndef _RESOLV_H
|
||||
#define _RESOLV_H
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
||||
#define RES_INIT 0x00000001
|
||||
#define RES_DEBUG 0x00000002
|
||||
#define RES_USEVC 0x00000008
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <string.h>
|
||||
|
||||
#include <mlibc/debug.hpp>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/internal-sysdeps.hpp>
|
||||
|
||||
namespace {
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/internal-sysdeps.hpp>
|
||||
|
||||
typedef void (*InitPtr)();
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <bits/ensure.h>
|
||||
#include <frg/eternal.hpp>
|
||||
#include <mlibc/allocator.hpp>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/internal-sysdeps.hpp>
|
||||
|
||||
// --------------------------------------------------------
|
||||
// Globals
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
#include <bits/ensure.h>
|
||||
#include <mlibc/debug.hpp>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/internal-sysdeps.hpp>
|
||||
|
||||
namespace mlibc {
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
#include <bits/ensure.h>
|
||||
#include <mlibc/debug.hpp>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/internal-sysdeps.hpp>
|
||||
|
||||
extern "C" void frg_panic(const char *mstr) {
|
||||
// mlibc::sys_libc_log("mlibc: Call to frg_panic");
|
||||
|
|
31
options/internal/include/mlibc/all-sysdeps.hpp
Normal file
31
options/internal/include/mlibc/all-sysdeps.hpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
#ifndef MLIBC_ALL_SYSDEPS
|
||||
#define MLIBC_ALL_SYSDEPS
|
||||
|
||||
#include <bits/feature.h>
|
||||
#include <internal-config.h>
|
||||
|
||||
#if __MLIBC_ANSI_OPTION
|
||||
# include <mlibc/ansi-sysdeps.hpp>
|
||||
#endif // __MLIBC_ANSI_OPTION
|
||||
|
||||
#if __MLIBC_POSIX_OPTION
|
||||
# include <mlibc/posix-sysdeps.hpp>
|
||||
#endif // __MLIBC_POSIX_OPTION
|
||||
|
||||
#if __MLIBC_LINUX_OPTION
|
||||
# include <mlibc/linux-sysdeps.hpp>
|
||||
#endif // __MLIBC_LINUX_OPTION
|
||||
|
||||
#ifdef MLIBC_BUILDING_RTDL
|
||||
# include <mlibc/rtdl-sysdeps.hpp>
|
||||
#endif // MLIBC_BUILDING_RTDL
|
||||
|
||||
// TODO(geert): Make glibc optional
|
||||
// Fixes this hack which works around rtdl not
|
||||
// including the glibc option
|
||||
#ifndef MLIBC_BUILDING_RTDL
|
||||
# include <mlibc/glibc-sysdeps.hpp>
|
||||
#endif // !MLIBC_BUILDING_RTDL
|
||||
#include <mlibc/internal-sysdeps.hpp>
|
||||
|
||||
#endif // MLIBC_ALL_SYSDEPS
|
34
options/internal/include/mlibc/bitutil.hpp
Normal file
34
options/internal/include/mlibc/bitutil.hpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
#ifndef MLIBC_BITUTIL
|
||||
#define MLIBC_BITUTIL
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace mlibc {
|
||||
|
||||
template<typename T>
|
||||
struct bit_util;
|
||||
|
||||
template<>
|
||||
struct bit_util<uint64_t> {
|
||||
static uint64_t byteswap(uint64_t x) {
|
||||
return __builtin_bswap64(x);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct bit_util<uint32_t> {
|
||||
static uint32_t byteswap(uint32_t x) {
|
||||
return __builtin_bswap32(x);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct bit_util<uint16_t> {
|
||||
static uint16_t byteswap(uint16_t x) {
|
||||
return __builtin_bswap16(x);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace mlibc
|
||||
|
||||
#endif // MLIBC_BITUTIL
|
|
@ -1,15 +1,16 @@
|
|||
#ifndef MLIBC_FILE_WINDOW
|
||||
#define MLIBC_FILE_WINDOW
|
||||
|
||||
#include <abi-bits/abi.h>
|
||||
#include <mlibc/allocator.hpp>
|
||||
#include <mlibc/debug.hpp>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/internal-sysdeps.hpp>
|
||||
#include <internal-config.h>
|
||||
|
||||
struct file_window {
|
||||
file_window(const char *path) {
|
||||
int fd;
|
||||
if(mlibc::sys_open("/etc/localtime", O_RDONLY, &fd))
|
||||
if(mlibc::sys_open("/etc/localtime", __MLIBC_O_RDONLY, &fd))
|
||||
mlibc::panicLogger() << "mlibc: Error opening file_window to "
|
||||
<< path << frg::endlog;
|
||||
|
||||
|
|
15
options/internal/include/mlibc/fsfd_target.hpp
Normal file
15
options/internal/include/mlibc/fsfd_target.hpp
Normal file
|
@ -0,0 +1,15 @@
|
|||
#ifndef MLIBC_FSFD_TARGET
|
||||
#define MLIBC_FSFD_TARGET
|
||||
|
||||
namespace mlibc {
|
||||
|
||||
enum class fsfd_target {
|
||||
none,
|
||||
path,
|
||||
fd,
|
||||
fd_path
|
||||
};
|
||||
|
||||
} // namespace mlibc
|
||||
|
||||
#endif // MLIBC_FSFD_TARGET
|
40
options/internal/include/mlibc/internal-sysdeps.hpp
Normal file
40
options/internal/include/mlibc/internal-sysdeps.hpp
Normal file
|
@ -0,0 +1,40 @@
|
|||
#ifndef MLIBC_INTERNAL_SYSDEPS
|
||||
#define MLIBC_INTERNAL_SYSDEPS
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <abi-bits/seek-whence.h>
|
||||
#include <abi-bits/vm-flags.h>
|
||||
#include <bits/off_t.h>
|
||||
#include <bits/ssize_t.h>
|
||||
#include <abi-bits/stat.h>
|
||||
#include <mlibc/fsfd_target.hpp>
|
||||
|
||||
namespace mlibc [[gnu::visibility("hidden")]] {
|
||||
|
||||
void sys_libc_log(const char *message);
|
||||
[[noreturn]] void sys_libc_panic();
|
||||
|
||||
int sys_tcb_set(void *pointer);
|
||||
|
||||
[[gnu::weak]] int sys_futex_tid();
|
||||
int sys_futex_wait(int *pointer, int expected);
|
||||
int sys_futex_wake(int *pointer);
|
||||
|
||||
int sys_anon_allocate(size_t size, void **pointer);
|
||||
int sys_anon_free(void *pointer, size_t size);
|
||||
|
||||
int sys_open(const char *pathname, int flags, int *fd);
|
||||
int sys_read(int fd, void *buf, size_t count, ssize_t *bytes_read);
|
||||
int sys_seek(int fd, off_t offset, int whence, off_t *new_offset);
|
||||
int sys_close(int fd);
|
||||
|
||||
[[gnu::weak]] int sys_stat(fsfd_target fsfdt, int fd, const char *path, int flags,
|
||||
struct stat *statbuf);
|
||||
// mlibc assumes that anonymous memory returned by sys_vm_map() is zeroed by the kernel / whatever is behind the sysdeps
|
||||
int sys_vm_map(void *hint, size_t size, int prot, int flags, int fd, off_t offset, void **window);
|
||||
int sys_vm_unmap(void *pointer, size_t size);
|
||||
|
||||
} //namespace mlibc
|
||||
|
||||
#endif // MLIBC_INTERNAL_SYSDEPS
|
|
@ -2,7 +2,7 @@
|
|||
#define MLIBC_LOCK_HPP
|
||||
|
||||
#include <stdint.h>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/internal-sysdeps.hpp>
|
||||
#include <bits/ensure.h>
|
||||
|
||||
struct FutexLock {
|
||||
|
|
|
@ -1,196 +0,0 @@
|
|||
#ifndef MLIBC_SYSDEPS
|
||||
#define MLIBC_SYSDEPS
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <abi-bits/seek-whence.h>
|
||||
#include <abi-bits/vm-flags.h>
|
||||
#include <bits/posix/off_t.h>
|
||||
#include <bits/posix/ssize_t.h>
|
||||
|
||||
#ifndef MLIBC_BUILDING_RTDL
|
||||
# include <fcntl.h>
|
||||
# include <time.h>
|
||||
# include <bits/posix/pid_t.h>
|
||||
# include <bits/posix/socklen_t.h>
|
||||
# include <bits/posix/stat.h>
|
||||
# include <poll.h>
|
||||
# include <stdarg.h>
|
||||
# include <sys/epoll.h>
|
||||
# include <sys/socket.h>
|
||||
# include <sys/resource.h>
|
||||
# include <sys/select.h>
|
||||
# include <termios.h>
|
||||
# include <time.h>
|
||||
#endif
|
||||
|
||||
namespace mlibc [[gnu::visibility("hidden")]] {
|
||||
|
||||
enum class fsfd_target {
|
||||
none,
|
||||
path,
|
||||
fd,
|
||||
fd_path
|
||||
};
|
||||
|
||||
void sys_libc_log(const char *message);
|
||||
[[noreturn]] void sys_libc_panic();
|
||||
|
||||
[[gnu::weak]] int sys_futex_tid();
|
||||
int sys_futex_wait(int *pointer, int expected);
|
||||
int sys_futex_wake(int *pointer);
|
||||
|
||||
int sys_tcb_set(void *pointer);
|
||||
|
||||
int sys_anon_allocate(size_t size, void **pointer);
|
||||
int sys_anon_free(void *pointer, size_t size);
|
||||
|
||||
#ifndef MLIBC_BUILDING_RTDL
|
||||
[[noreturn]] void sys_exit(int status);
|
||||
[[noreturn, gnu::weak]] void sys_thread_exit();
|
||||
int sys_clock_get(int clock, time_t *secs, long *nanos);
|
||||
#endif // !defined(MLIBC_BUILDING_RTDL)
|
||||
|
||||
int sys_open(const char *pathname, int flags, int *fd);
|
||||
[[gnu::weak]] int sys_flock(int fd, int options);
|
||||
|
||||
#ifndef MLIBC_BUILDING_RTDL
|
||||
[[gnu::weak]] int sys_open_dir(const char *path, int *handle);
|
||||
[[gnu::weak]] int sys_read_entries(int handle, void *buffer, size_t max_size,
|
||||
size_t *bytes_read);
|
||||
#endif // !defined(MLIBC_BUILDING_RTDL)
|
||||
|
||||
int sys_read(int fd, void *buf, size_t count, ssize_t *bytes_read);
|
||||
|
||||
#ifndef MLIBC_BUILDING_RTDL
|
||||
int sys_write(int fd, const void *buf, size_t count, ssize_t *bytes_written);
|
||||
[[gnu::weak]] int sys_pread(int fd, void *buf, size_t n, off_t off, ssize_t *bytes_read);
|
||||
#endif // !defined(MLIBC_BUILDING_RTDL)
|
||||
|
||||
int sys_seek(int fd, off_t offset, int whence, off_t *new_offset);
|
||||
int sys_close(int fd);
|
||||
|
||||
#ifndef MLIBC_BUILDING_RTDL
|
||||
[[gnu::weak]] int sys_access(const char *path, int mode);
|
||||
[[gnu::weak]] int sys_faccessat(int dirfd, const char *pathname, int mode, int flags);
|
||||
[[gnu::weak]] int sys_dup(int fd, int flags, int *newfd);
|
||||
[[gnu::weak]] int sys_dup2(int fd, int flags, int newfd);
|
||||
// In contrast to the isatty() library function, the sysdep function uses return value
|
||||
// zero (and not one) to indicate that the file is a terminal.
|
||||
[[gnu::weak]] int sys_isatty(int fd);
|
||||
[[gnu::weak]] int sys_stat(fsfd_target fsfdt, int fd, const char *path, int flags,
|
||||
struct stat *statbuf);
|
||||
[[gnu::weak]] int sys_readlink(const char *path, void *buffer, size_t max_size, ssize_t *length);
|
||||
[[gnu::weak]] int sys_rmdir(const char *path);
|
||||
[[gnu::weak]] int sys_ftruncate(int fd, size_t size);
|
||||
[[gnu::weak]] int sys_fallocate(int fd, off_t offset, size_t size);
|
||||
[[gnu::weak]] int sys_unlink(const char *path);
|
||||
[[gnu::weak]] int sys_unlinkat(int fd, const char *path, int flags);
|
||||
[[gnu::weak]] int sys_openat(int dirfd, const char *path, int flags, int *fd);
|
||||
[[gnu::weak]] int sys_socket(int family, int type, int protocol, int *fd);
|
||||
[[gnu::weak]] int sys_msg_send(int fd, const struct msghdr *hdr, int flags, ssize_t *length);
|
||||
[[gnu::weak]] int sys_msg_recv(int fd, struct msghdr *hdr, int flags, ssize_t *length);
|
||||
[[gnu::weak]] int sys_listen(int fd, int backlog);
|
||||
[[gnu::weak]] gid_t sys_getgid();
|
||||
[[gnu::weak]] gid_t sys_getegid();
|
||||
[[gnu::weak]] uid_t sys_getuid();
|
||||
[[gnu::weak]] uid_t sys_geteuid();
|
||||
[[gnu::weak]] pid_t sys_getpid();
|
||||
[[gnu::weak]] pid_t sys_getppid();
|
||||
[[gnu::weak]] pid_t sys_getpgrp();
|
||||
[[gnu::weak]] int sys_setuid(uid_t uid);
|
||||
[[gnu::weak]] int sys_seteuid(uid_t euid);
|
||||
[[gnu::weak]] int sys_setgid(gid_t gid);
|
||||
[[gnu::weak]] int sys_setegid(gid_t egid);
|
||||
[[gnu::weak]] void sys_yield();
|
||||
[[gnu::weak]] int sys_sleep(time_t *secs, long *nanos);
|
||||
[[gnu::weak]] int sys_fork(pid_t *child);
|
||||
[[gnu::weak]] int sys_clone(void *entry, void *user_arg, void *tcb, pid_t *pid_out);
|
||||
[[gnu::weak]] int sys_execve(const char *path, char *const argv[], char *const envp[]);
|
||||
[[gnu::weak]] int sys_pselect(int num_fds, fd_set *read_set, fd_set *write_set,
|
||||
fd_set *except_set, const struct timespec *timeout, const sigset_t *sigmask, int *num_events);
|
||||
[[gnu::weak]] int sys_getrusage(int scope, struct rusage *usage);
|
||||
[[gnu::weak]] int sys_getrlimit(int resource, struct rlimit *limit);
|
||||
[[gnu::weak]] int sys_timerfd_create(int flags, int *fd);
|
||||
[[gnu::weak]] int sys_timerfd_settime(int fd, int flags,
|
||||
const struct itimerspec *value);
|
||||
[[gnu::weak]] int sys_signalfd_create(sigset_t, int flags, int *fd);
|
||||
[[gnu::weak]] int sys_getcwd(char *buffer, size_t size);
|
||||
[[gnu::weak]] int sys_chdir(const char *path);
|
||||
[[gnu::weak]] int sys_fchdir(int fd);
|
||||
[[gnu::weak]] int sys_chroot(const char *path);
|
||||
[[gnu::weak]] int sys_mkdir(const char *path);
|
||||
[[gnu::weak]] int sys_mkdirat(int dirfd, const char *path, mode_t mode);
|
||||
[[gnu::weak]] int sys_link(const char *old_path, const char *new_path);
|
||||
[[gnu::weak]] int sys_linkat(int olddirfd, const char *old_path, int newdirfd, const char *new_path, int flags);
|
||||
[[gnu::weak]] int sys_symlink(const char *target_path, const char *link_path);
|
||||
[[gnu::weak]] int sys_symlinkat(const char *target_path, int dirfd, const char *link_path);
|
||||
[[gnu::weak]] int sys_rename(const char *path, const char *new_path);
|
||||
[[gnu::weak]] int sys_renameat(int olddirfd, const char *old_path, int newdirfd, const char *new_path);
|
||||
[[gnu::weak]] int sys_fcntl(int fd, int request, va_list args, int *result);
|
||||
[[gnu::weak]] int sys_ttyname(int fd, char *buf, size_t size);
|
||||
[[gnu::weak]] int sys_fadvise(int fd, off_t offset, off_t length, int advice);
|
||||
[[gnu::weak]] int sys_fsync(int fd);
|
||||
[[gnu::weak]] int sys_chmod(const char *pathname, mode_t mode);
|
||||
[[gnu::weak]] int sys_fchmod(int fd, mode_t mode);
|
||||
[[gnu::weak]] int sys_fchmodat(int fd, const char *pathname, mode_t mode, int flags);
|
||||
[[gnu::weak]] int sys_utimensat(int dirfd, const char *pathname, const struct timespec times[2], int flags);
|
||||
#endif // !defined(MLIBC_BUILDING_RTDL)
|
||||
|
||||
// mlibc assumes that anonymous memory returned by sys_vm_map() is zeroed by the kernel / whatever is behind the sysdeps
|
||||
int sys_vm_map(void *hint, size_t size, int prot, int flags, int fd, off_t offset, void **window);
|
||||
|
||||
#ifndef MLIBC_BUILDING_RTDL
|
||||
[[gnu::weak]] int sys_vm_remap(void *pointer, size_t size, size_t new_size, void **window);
|
||||
[[gnu::weak]] int sys_vm_protect(void *pointer, size_t size, int prot);
|
||||
#endif // !defined(MLIBC_BUILDING_RTDL)
|
||||
|
||||
int sys_vm_unmap(void *pointer, size_t size);
|
||||
|
||||
[[gnu::weak]] int sys_vm_readahead(void *pointer, size_t size);
|
||||
|
||||
#ifndef MLIBC_BUILDING_RTDL
|
||||
[[gnu::weak]] int sys_setsid(pid_t *sid);
|
||||
[[gnu::weak]] int sys_tcgetattr(int fd, struct termios *attr);
|
||||
[[gnu::weak]] int sys_tcsetattr(int, int, const struct termios *attr);
|
||||
[[gnu::weak]] int sys_tcflow(int, int);
|
||||
[[gnu::weak]] int sys_pipe(int *fds, int flags);
|
||||
[[gnu::weak]] int sys_socketpair(int domain, int type_and_flags, int proto, int *fds);
|
||||
[[gnu::weak]] int sys_poll(struct pollfd *fds, nfds_t count, int timeout, int *num_events);
|
||||
[[gnu::weak]] int sys_epoll_create(int flags, int *fd);
|
||||
[[gnu::weak]] int sys_epoll_ctl(int epfd, int mode, int fd, struct epoll_event *ev);
|
||||
[[gnu::weak]] int sys_epoll_pwait(int epfd, struct epoll_event *ev, int n,
|
||||
int timeout, const sigset_t *sigmask, int *raised);
|
||||
[[gnu::weak]] int sys_inotify_create(int flags, int *fd);
|
||||
[[gnu::weak]] int sys_inotify_add_watch(int ifd, const char *path, uint32_t mask, int *wd);
|
||||
[[gnu::weak]] int sys_inotify_rm_watch(int ifd, int wd);
|
||||
[[gnu::weak]] int sys_ioctl(int fd, unsigned long request, void *arg, int *result);
|
||||
[[gnu::weak]] int sys_reboot(int cmd);
|
||||
[[gnu::weak]] int sys_getsockopt(int fd, int layer, int number,
|
||||
void *__restrict buffer, socklen_t *__restrict size);
|
||||
[[gnu::weak]] int sys_setsockopt(int fd, int layer, int number,
|
||||
const void *buffer, socklen_t size);
|
||||
[[gnu::weak]] int sys_waitpid(pid_t pid, int *status, int flags, pid_t *ret_pid);
|
||||
[[gnu::weak]] int sys_mount(const char *source, const char *target,
|
||||
const char *fstype, unsigned long flags, const void *data);
|
||||
[[gnu::weak]] int sys_sigprocmask(int how, const sigset_t *__restrict set,
|
||||
sigset_t *__restrict retrieve);
|
||||
[[gnu::weak]] int sys_sigaction(int, const struct sigaction *__restrict,
|
||||
struct sigaction *__restrict);
|
||||
[[gnu::weak]] int sys_kill(int, int);
|
||||
[[gnu::weak]] int sys_accept(int fd, int *newfd);
|
||||
[[gnu::weak]] int sys_bind(int fd, const struct sockaddr *addr_ptr, socklen_t addr_length);
|
||||
[[gnu::weak]] int sys_connect(int fd, const struct sockaddr *addr_ptr, socklen_t addr_length);
|
||||
[[gnu::weak]] int sys_sockname(int fd, struct sockaddr *addr_ptr, socklen_t max_addr_length,
|
||||
socklen_t *actual_length);
|
||||
[[gnu::weak]] int sys_peername(int fd, struct sockaddr *addr_ptr, socklen_t max_addr_length,
|
||||
socklen_t *actual_length);
|
||||
[[gnu::weak]] int sys_gethostname(char *buffer, size_t bufsize);
|
||||
[[gnu::weak]] int sys_mkfifoat(int dirfd, const char *path, int mode);
|
||||
[[gnu::weak]] int sys_eventfd_create(unsigned int initval, int flags, int *fd);
|
||||
[[gnu::weak]] int sys_getentropy(void *buffer, size_t length);
|
||||
#endif // !defined(MLIBC_BUILDING_RTDL)
|
||||
|
||||
} //namespace mlibc
|
||||
|
||||
#endif // MLIBC_SYSDEPS
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include <bits/ensure.h>
|
||||
#include <mlibc/debug.hpp>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/linux-sysdeps.hpp>
|
||||
|
||||
int poll(struct pollfd *fds, nfds_t count, int timeout) {
|
||||
int num_events;
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#include <mlibc/debug.hpp>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/linux-sysdeps.hpp>
|
||||
|
||||
int openpty(int *mfd, int *sfd, char *name, const struct termios *ios, const struct winsize *win) {
|
||||
__ensure(!name);
|
||||
|
@ -28,13 +28,13 @@ int openpty(int *mfd, int *sfd, char *name, const struct termios *ios, const str
|
|||
char spath[32];
|
||||
if(ptsname_r(ptmx_fd, spath, 32))
|
||||
return -1;
|
||||
|
||||
|
||||
int pts_fd;
|
||||
if(int e = mlibc::sys_open(spath, O_RDWR | O_NOCTTY, &pts_fd); e) {
|
||||
errno = e;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
*mfd = ptmx_fd;
|
||||
*sfd = pts_fd;
|
||||
return 0;
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
#include <sys/epoll.h>
|
||||
|
||||
#include <bits/ensure.h>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/linux-sysdeps.hpp>
|
||||
#include <stddef.h>
|
||||
|
||||
int epoll_create(int) {
|
||||
int fd;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include <errno.h>
|
||||
|
||||
#include <bits/ensure.h>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/linux-sysdeps.hpp>
|
||||
|
||||
int eventfd(unsigned int initval, int flags) {
|
||||
int fd = 0;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include <bits/ensure.h>
|
||||
#include <mlibc/debug.hpp>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/linux-sysdeps.hpp>
|
||||
|
||||
int inotify_init(void) {
|
||||
int fd;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <sys/mount.h>
|
||||
|
||||
#include <bits/ensure.h>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/linux-sysdeps.hpp>
|
||||
|
||||
int mount(const char *source, const char *target,
|
||||
const char *fstype, unsigned long flags, const void *data) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include <errno.h>
|
||||
#include <sys/reboot.h>
|
||||
#include <bits/ensure.h>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/linux-sysdeps.hpp>
|
||||
|
||||
int reboot(int what) {
|
||||
if (!mlibc::sys_reboot) {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <sys/signalfd.h>
|
||||
|
||||
#include <bits/ensure.h>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/linux-sysdeps.hpp>
|
||||
|
||||
int signalfd(int fd, const sigset_t *mask, int flags) {
|
||||
__ensure(fd == -1);
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include <bits/ensure.h>
|
||||
#include <mlibc/debug.hpp>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/linux-sysdeps.hpp>
|
||||
|
||||
int timerfd_create(int, int flags) {
|
||||
if(!mlibc::sys_timerfd_create) {
|
||||
|
|
38
options/linux/include/mlibc/linux-sysdeps.hpp
Normal file
38
options/linux/include/mlibc/linux-sysdeps.hpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
#ifndef MLIBC_LINUX_SYSDEPS
|
||||
#define MLIBC_LINUX_SYSDEPS
|
||||
|
||||
#include <sys/epoll.h>
|
||||
#include <poll.h>
|
||||
#include <abi-bits/pid_t.h>
|
||||
#include <bits/ssize_t.h>
|
||||
#include <bits/size_t.h>
|
||||
|
||||
namespace mlibc [[gnu::visibility("default")]] {
|
||||
|
||||
int sys_open(const char *pathname, int flags, int *fd);
|
||||
int sys_close(int fd);
|
||||
int sys_read(int fd, void *buf, size_t count, ssize_t *bytes_read);
|
||||
int sys_write(int fd, const void *buf, size_t count, ssize_t *bytes_written);
|
||||
|
||||
[[gnu::weak]] int sys_dup2(int fd, int flags, int newfd);
|
||||
[[gnu::weak]] int sys_fork(pid_t *child);
|
||||
[[gnu::weak]] int sys_inotify_create(int flags, int *fd);
|
||||
[[gnu::weak]] int sys_inotify_add_watch(int ifd, const char *path, uint32_t mask, int *wd);
|
||||
[[gnu::weak]] int sys_inotify_rm_watch(int ifd, int wd);
|
||||
[[gnu::weak]] int sys_epoll_create(int flags, int *fd);
|
||||
[[gnu::weak]] int sys_epoll_ctl(int epfd, int mode, int fd, struct epoll_event *ev);
|
||||
[[gnu::weak]] int sys_epoll_pwait(int epfd, struct epoll_event *ev, int n,
|
||||
int timeout, const sigset_t *sigmask, int *raised);
|
||||
[[gnu::weak]] int sys_poll(struct pollfd *fds, nfds_t count, int timeout, int *num_events);
|
||||
[[gnu::weak]] int sys_mount(const char *source, const char *target,
|
||||
const char *fstype, unsigned long flags, const void *data);
|
||||
[[gnu::weak]] int sys_eventfd_create(unsigned int initval, int flags, int *fd);
|
||||
[[gnu::weak]] int sys_timerfd_create(int flags, int *fd);
|
||||
[[gnu::weak]] int sys_timerfd_settime(int fd, int flags,
|
||||
const struct itimerspec *value);
|
||||
[[gnu::weak]] int sys_signalfd_create(sigset_t, int flags, int *fd);
|
||||
[[gnu::weak]] int sys_reboot(int cmd);
|
||||
|
||||
} // namespace mlibc
|
||||
|
||||
#endif // MLIBX_LINUX_SYSDEPS
|
|
@ -9,7 +9,7 @@ extern "C" {
|
|||
#define GRND_RANDOM 1
|
||||
#define GRND_NONBLOCK 2
|
||||
|
||||
#include <bits/posix/ssize_t.h>
|
||||
#include <bits/ssize_t.h>
|
||||
#include <bits/size_t.h>
|
||||
|
||||
ssize_t getrandom(void *, size_t, unsigned int);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef _UTMP_H
|
||||
#define _UTMP_H
|
||||
|
||||
#include <bits/posix/pid_t.h>
|
||||
#include <abi-bits/pid_t.h>
|
||||
#include <bits/posix/timeval.h>
|
||||
#include <bits/types.h>
|
||||
|
||||
|
|
|
@ -6,54 +6,34 @@
|
|||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace {
|
||||
|
||||
template<typename T>
|
||||
struct bit_util;
|
||||
|
||||
template<>
|
||||
struct bit_util<uint32_t> {
|
||||
static uint32_t byteswap(uint32_t x) {
|
||||
return __builtin_bswap32(x);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct bit_util<uint16_t> {
|
||||
static uint16_t byteswap(uint16_t x) {
|
||||
return __builtin_bswap16(x);
|
||||
}
|
||||
};
|
||||
|
||||
} // anonymous namespace
|
||||
#include <mlibc/bitutil.hpp>
|
||||
|
||||
const struct in6_addr in6addr_any = {{}};
|
||||
|
||||
uint32_t htonl(uint32_t x) {
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
return bit_util<uint32_t>::byteswap(x);
|
||||
return mlibc::bit_util<uint32_t>::byteswap(x);
|
||||
#else
|
||||
return x;
|
||||
#endif
|
||||
}
|
||||
uint16_t htons(uint16_t x) {
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
return bit_util<uint16_t>::byteswap(x);
|
||||
return mlibc::bit_util<uint16_t>::byteswap(x);
|
||||
#else
|
||||
return x;
|
||||
#endif
|
||||
}
|
||||
uint32_t ntohl(uint32_t x) {
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
return bit_util<uint32_t>::byteswap(x);
|
||||
return mlibc::bit_util<uint32_t>::byteswap(x);
|
||||
#else
|
||||
return x;
|
||||
#endif
|
||||
}
|
||||
uint16_t ntohs(uint16_t x) {
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
return bit_util<uint16_t>::byteswap(x);
|
||||
return mlibc::bit_util<uint16_t>::byteswap(x);
|
||||
#else
|
||||
return x;
|
||||
#endif
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include <bits/ensure.h>
|
||||
#include <frg/allocation.hpp>
|
||||
#include <mlibc/allocator.hpp>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/posix-sysdeps.hpp>
|
||||
#include <mlibc/debug.hpp>
|
||||
|
||||
int alphasort(const struct dirent **, const struct dirent **) {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <stdarg.h>
|
||||
|
||||
#include <mlibc/debug.hpp>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/posix-sysdeps.hpp>
|
||||
|
||||
int creat(const char *pathname, mode_t mode) {
|
||||
return open(pathname, O_CREAT|O_WRONLY|O_TRUNC, mode);
|
||||
|
|
13
options/posix/generic/posix_locale.cpp
Normal file
13
options/posix/generic/posix_locale.cpp
Normal file
|
@ -0,0 +1,13 @@
|
|||
#include <bits/posix/posix_locale.h>
|
||||
#include <bits/ensure.h>
|
||||
|
||||
locale_t newlocale(int category_mask, const char *locale, locale_t base) {
|
||||
__ensure(!"Not implemented");
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void freelocale(locale_t locobj) {
|
||||
__ensure(!"Not implemented");
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
#include <signal.h>
|
||||
#include <bits/ensure.h>
|
||||
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/posix-sysdeps.hpp>
|
||||
|
||||
int sigemptyset(sigset_t *sigset) {
|
||||
*sigset = 0;
|
||||
|
|
|
@ -48,3 +48,18 @@ off_t ftello(FILE *file_base) {
|
|||
return current_offset;
|
||||
}
|
||||
|
||||
int dprintf(int fd, const char *format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
int result = vdprintf(fd, format, args);
|
||||
va_end(args);
|
||||
return result;
|
||||
}
|
||||
|
||||
int vdprintf(int fd, const char *format, __gnuc_va_list args) {
|
||||
FILE *file = fdopen(fd, "a");
|
||||
int ret = vfprintf(file, format, args);
|
||||
fclose(file);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#include <frg/vector.hpp>
|
||||
#include <mlibc/allocator.hpp>
|
||||
#include <mlibc/debug.hpp>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/posix-sysdeps.hpp>
|
||||
|
||||
namespace {
|
||||
constexpr bool debugPathResolution = false;
|
||||
|
@ -403,3 +403,7 @@ int grantpt(int fd) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
double strtod_l(const char *__restrict__ nptr, char ** __restrict__ endptr, locale_t loc) {
|
||||
__ensure(!"Not implemented");
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
|
32
options/posix/generic/posix_time.cpp
Normal file
32
options/posix/generic/posix_time.cpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
#include <bits/posix/posix_time.h>
|
||||
#include <bits/ensure.h>
|
||||
#include <mlibc/posix-sysdeps.hpp>
|
||||
#include <errno.h>
|
||||
|
||||
int utimes(const char *filename, const struct timeval times[2]) {
|
||||
if (!mlibc::sys_utimensat) {
|
||||
MLIBC_MISSING_SYSDEP();
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
struct timespec time[2];
|
||||
if(times == nullptr) {
|
||||
time[0].tv_sec = UTIME_NOW;
|
||||
time[0].tv_nsec = UTIME_NOW;
|
||||
time[1].tv_sec = UTIME_NOW;
|
||||
time[1].tv_nsec = UTIME_NOW;
|
||||
} else {
|
||||
time[0].tv_sec = times[0].tv_sec;
|
||||
time[0].tv_nsec = times[0].tv_usec * 1000;
|
||||
time[1].tv_sec = times[1].tv_sec;
|
||||
time[1].tv_nsec = times[1].tv_usec * 1000;
|
||||
}
|
||||
|
||||
if (int e = mlibc::sys_utimensat(AT_FDCWD, filename, time, 0); e) {
|
||||
errno = e;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
#include <frg/hash_map.hpp>
|
||||
#include <mlibc/allocator.hpp>
|
||||
#include <mlibc/debug.hpp>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/posix-sysdeps.hpp>
|
||||
#include <mlibc/thread.hpp>
|
||||
#include <mlibc/tcb.hpp>
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <sched.h>
|
||||
|
||||
#include <mlibc/debug.hpp>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/posix-sysdeps.hpp>
|
||||
|
||||
int sched_yield(void) {
|
||||
if(mlibc::sys_yield) {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <bits/ensure.h>
|
||||
#include <mlibc/debug.hpp>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/posix-sysdeps.hpp>
|
||||
|
||||
static constexpr unsigned int semaphoreHasWaiters = static_cast<uint32_t>(1 << 31);
|
||||
static constexpr unsigned int semaphoreCountMask = static_cast<uint32_t>(1 << 31) - 1;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
#include <sys/file.h>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/posix-sysdeps.hpp>
|
||||
#include <errno.h>
|
||||
|
||||
#include <bits/ensure.h>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <bits/ensure.h>
|
||||
|
||||
#include <mlibc/debug.hpp>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/posix-sysdeps.hpp>
|
||||
|
||||
int mprotect(void *pointer, size_t size, int prot) {
|
||||
if(!mlibc::sys_vm_protect) {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <sys/resource.h>
|
||||
|
||||
#include <bits/ensure.h>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/posix-sysdeps.hpp>
|
||||
|
||||
int getpriority(int, id_t) {
|
||||
__ensure(!"Not implemented");
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include <bits/ensure.h>
|
||||
#include <bits/feature.h>
|
||||
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/posix-sysdeps.hpp>
|
||||
|
||||
void FD_CLR(int fd, fd_set *set) {
|
||||
__ensure(fd < FD_SETSIZE);
|
||||
|
@ -27,8 +27,6 @@ void FD_ZERO(fd_set *set) {
|
|||
memset(set->__mlibc_elems, 0, sizeof(fd_set));
|
||||
}
|
||||
|
||||
// select() is currently implemented on top of epoll.
|
||||
// TODO: Provide a sys_select() function instead.
|
||||
int select(int num_fds, fd_set *__restrict read_set, fd_set *__restrict write_set,
|
||||
fd_set *__restrict except_set, struct timeval *__restrict timeout) {
|
||||
if(!mlibc::sys_pselect) {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include <bits/ensure.h>
|
||||
#include <mlibc/debug.hpp>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/posix-sysdeps.hpp>
|
||||
|
||||
int accept(int fd, struct sockaddr *__restrict addr_ptr, socklen_t *__restrict addr_length) {
|
||||
if(addr_ptr || addr_length)
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <sys/stat.h>
|
||||
|
||||
#include <mlibc/debug.hpp>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/posix-sysdeps.hpp>
|
||||
|
||||
int chmod(const char *pathname, mode_t mode) {
|
||||
if(!mlibc::sys_chmod) {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#include <bits/ensure.h>
|
||||
#include <mlibc/debug.hpp>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/posix-sysdeps.hpp>
|
||||
|
||||
int gettimeofday(struct timeval *__restrict result, void *__restrict unused) {
|
||||
(void)unused; // Linux just ignores gettimeofday().
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <sys/wait.h>
|
||||
#include <bits/ensure.h>
|
||||
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/posix-sysdeps.hpp>
|
||||
|
||||
int waitid(idtype_t idtype, id_t id, siginfo_t *siginfo, int flags) {
|
||||
__ensure(!"Not implemented");
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <termios.h>
|
||||
|
||||
#include <bits/ensure.h>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/posix-sysdeps.hpp>
|
||||
|
||||
speed_t cfgetispeed(const struct termios *tios) {
|
||||
return tios->ibaud;
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include <mlibc/allocator.hpp>
|
||||
#include <mlibc/arch-defs.hpp>
|
||||
#include <mlibc/debug.hpp>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/posix-sysdeps.hpp>
|
||||
|
||||
unsigned int alarm(unsigned int seconds) {
|
||||
__ensure(!"Not implemented");
|
||||
|
@ -58,7 +58,7 @@ ssize_t confstr(int name, char *buf, size_t len) {
|
|||
return 0;
|
||||
} else {
|
||||
mlibc::infoLogger() << "\e[31mmlibc: confstr() request " << name << " is unimplemented\e[39m"
|
||||
<< frg::endlog;
|
||||
<< frg::endlog;
|
||||
__ensure(!"Not implemented");
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <errno.h>
|
||||
|
||||
#include <bits/ensure.h>
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
#include <mlibc/posix-sysdeps.hpp>
|
||||
|
||||
int utime(const char *filename, const struct utimbuf *times) {
|
||||
if (!mlibc::sys_utimensat) {
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
#ifndef MLIBC_BLKCNT_T_H
|
||||
#define MLIBC_BLKCNT_T_H
|
||||
|
||||
// TODO: use int64_t?
|
||||
typedef long blkcnt_t;
|
||||
|
||||
#endif // MLIBC_BLKCNT_T_H
|
|
@ -1,9 +0,0 @@
|
|||
|
||||
#ifndef MLIBC_BLKSIZE_T_H
|
||||
#define MLIBC_BLKSIZE_T_H
|
||||
|
||||
// TODO: use int64_t?
|
||||
typedef long blksize_t;
|
||||
|
||||
#endif // MLIBC_BLKSIZE_T_H
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
|
||||
#ifndef MLIBC_DEV_T_H
|
||||
#define MLIBC_DEV_T_H
|
||||
|
||||
typedef unsigned long dev_t;
|
||||
|
||||
#endif // MLIBC_DEV_T_H
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
|
||||
#ifndef MLIBC_GID_T_H
|
||||
#define MLIBC_GID_T_H
|
||||
|
||||
typedef int gid_t;
|
||||
|
||||
#endif // MLIBC_GID_T_H
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
|
||||
#ifndef MLIBC_INO_T_H
|
||||
#define MLIBC_INO_T_H
|
||||
|
||||
// TODO: use (u)int64_t?
|
||||
typedef long ino_t;
|
||||
|
||||
#endif // MLIBC_INO_T_H
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
|
||||
#ifndef MLIBC_MODE_T_H
|
||||
#define MLIBC_MODE_T_H
|
||||
|
||||
typedef int mode_t;
|
||||
|
||||
#endif // MLIBC_MODE_T_H
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
|
||||
#ifndef MLIBC_NLINK_T_H
|
||||
#define MLIBC_NLINK_T_H
|
||||
|
||||
typedef int nlink_t;
|
||||
|
||||
#endif // MLIBC_NLINK_T_H
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
|
||||
#ifndef MLIBC_PID_T_H
|
||||
#define MLIBC_PID_T_H
|
||||
|
||||
typedef int pid_t;
|
||||
|
||||
#endif // MLIBC_PID_T_H
|
||||
|
17
options/posix/include/bits/posix/posix_locale.h
Normal file
17
options/posix/include/bits/posix/posix_locale.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
#ifndef MLIBC_POSIX_LOCALE_H
|
||||
#define MLIBC_POSIX_LOCALE_H
|
||||
|
||||
#include <bits/posix/locale_t.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
locale_t newlocale(int category_mask, const char *locale, locale_t base);
|
||||
void freelocale(locale_t locobj);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // MLIBC_POSIX_LOCALE_H
|
|
@ -2,8 +2,8 @@
|
|||
#ifndef MLIBC_POSIX_STDIO_H
|
||||
#define MLIBC_POSIX_STDIO_H
|
||||
|
||||
#include <bits/posix/off_t.h>
|
||||
#include <bits/posix/ssize_t.h>
|
||||
#include <bits/off_t.h>
|
||||
#include <bits/ssize_t.h>
|
||||
|
||||
// MISSING: var_list
|
||||
|
||||
|
@ -14,7 +14,7 @@ extern "C" {
|
|||
#define P_tmpdir "/tmp"
|
||||
|
||||
int fileno(FILE *file);
|
||||
FILE *fdopen(int fd, const char *mode);
|
||||
FILE *fdopen(int fd, const char *mode);
|
||||
|
||||
FILE *fmemopen(void *__restrict, size_t, const char *__restrict);
|
||||
int pclose(FILE *);
|
||||
|
@ -25,6 +25,7 @@ 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, __gnuc_va_list args);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
#ifndef MLIBC_POSIX_STDLIB_H
|
||||
#define MLIBC_POSIX_STDLIB_H
|
||||
|
||||
#include <bits/posix/locale_t.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -41,6 +43,8 @@ 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);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue