diff --git a/LibC/Makefile b/LibC/Makefile index 39ff6620fb10a0861b39cccad1ad5b7fe90bf674..360a1ab65c00e4ca78d395e3323c4568dee6a49f 100644 --- a/LibC/Makefile +++ b/LibC/Makefile @@ -20,6 +20,7 @@ LIBC_OBJS = \ getopt.o \ scanf.o \ pwd.o \ + times.o \ entry.o OBJS = $(AK_OBJS) $(LIBC_OBJS) diff --git a/LibC/endian.h b/LibC/endian.h new file mode 100644 index 0000000000000000000000000000000000000000..7bc4e0740851a65d6d1fb39cf9caab0e8f63b2ca --- /dev/null +++ b/LibC/endian.h @@ -0,0 +1,11 @@ +#pragma once + +#include + +__BEGIN_DECLS + +#define LITTLE_ENDIAN 1234 +#define BIG_ENDIAN 4321 +#define BYTE_ORDER LITTLE_ENDIAN + +__END_DECLS diff --git a/LibC/fcntl.h b/LibC/fcntl.h index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..cf679753cbada62a74c27e94c32db697bd96b1c2 100644 --- a/LibC/fcntl.h +++ b/LibC/fcntl.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +__BEGIN_DECLS + +#define F_DUPFD 0 +#define F_GETFD 1 +#define F_SETFD 2 +#define F_GETFL 3 +#define F_SETFL 4 + +__END_DECLS diff --git a/LibC/scanf.cpp b/LibC/scanf.cpp index 23c673c71a73d3e93de4d88d535b51de0ed730cc..b9b4726b7b92ed843e2ec4f435e6666701d04376 100644 --- a/LibC/scanf.cpp +++ b/LibC/scanf.cpp @@ -189,7 +189,7 @@ static int vsscanf(const char *buf, const char *s, va_list ap) for (tc = s; isdigit(*s); s++); strncpy (tmp, tc, s - tc); tmp[s - tc] = '\0'; - atob ((dword*)&width, tmp, 10); + atob ((uint32_t*)&width, tmp, 10); s--; } } @@ -232,7 +232,7 @@ static int vsscanf(const char *buf, const char *s, va_list ap) tmp[width] = '\0'; buf += width; if (!noassign) - atob(va_arg(ap, dword*), tmp, base); + atob(va_arg(ap, uint32_t*), tmp, base); } if (!noassign) ++count; diff --git a/LibC/setjmp.cpp b/LibC/setjmp.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/LibC/setjmp.h b/LibC/setjmp.h index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..eef107ebb46fe5d2b36ea38f83d153edcdad2d82 100644 --- a/LibC/setjmp.h +++ b/LibC/setjmp.h @@ -0,0 +1,13 @@ +#pragma once + +#include +#include + +__BEGIN_DECLS + +typedef uint32_t jmp_buf[6]; + +int setjmp(jmp_buf); +void longjmp(jmp_buf, int val); + +__END_DECLS diff --git a/LibC/signal.cpp b/LibC/signal.cpp index ab73f4a5e87c10d9a05f7061ef55149cfa067686..76442ed3ec6d3cb2274b93292e6c9cae329212e6 100644 --- a/LibC/signal.cpp +++ b/LibC/signal.cpp @@ -1,5 +1,6 @@ -#include "unistd.h" -#include "errno.h" +#include +#include +#include #include extern "C" { diff --git a/LibC/signal.h b/LibC/signal.h index 73e7eeaa43a903a33e613252c08d015259154307..0e36c40f19421bca622bd49b8b64982927639147 100644 --- a/LibC/signal.h +++ b/LibC/signal.h @@ -4,8 +4,31 @@ __BEGIN_DECLS +typedef void (*__sighandler_t)(int); +typedef __sighandler_t sighandler_t; + +typedef uint32_t sigset_t; +typedef void siginfo_t; + +struct sigaction { + void (*sa_handler)(int); + void (*sa_sigaction)(int, siginfo_t*, void*); + sigset_t sa_mask; + int sa_flags; + void (*sa_restorer)(void); +}; + int kill(pid_t, int sig); +#define SIG_DFL ((__sighandler_t)0) +#define SIG_ERR ((__sighandler_t)-1) +#define SIG_IGN ((__sighandler_t)1) + +#define SIG_BLOCK 0 +#define SIG_UNBLOCK 1 +#define SIG_SETMASK 2 + + #define SIGHUP 1 #define SIGINT 2 #define SIGQUIT 3 diff --git a/LibC/stddef.h b/LibC/stddef.h new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/LibC/stdint.h b/LibC/stdint.h new file mode 100644 index 0000000000000000000000000000000000000000..7deb47e5da2be4def01f7be626be6a93b12e71e5 --- /dev/null +++ b/LibC/stdint.h @@ -0,0 +1,16 @@ +#pragma once + +#include + +__BEGIN_DECLS + +typedef unsigned int uint32_t; +typedef unsigned short uint16_t; +typedef unsigned char uint8_t; + +typedef signed int int32_t; +typedef signed short int16_t; +typedef signed char int8_t; + +__END_DECLS + diff --git a/LibC/stdio.h b/LibC/stdio.h index c681f6ad185f82e792470708756c6c06009c1f7b..8ad7074a39ab8a014c01187683a4001d4f18b5e8 100644 --- a/LibC/stdio.h +++ b/LibC/stdio.h @@ -43,6 +43,7 @@ int sprintf(char* buffer, const char* fmt, ...); int putchar(int ch); void perror(const char*); int sscanf (const char* buf, const char* fmt, ...); +int fscanf(FILE*, const char* fmt, ...); __END_DECLS diff --git a/LibC/string.cpp b/LibC/string.cpp index ebd632c70ba0b79aa15269ad2d4ba00c545ba760..c79ec1d02675a5d40c9b0ac19253ffe9b5fbecba 100644 --- a/LibC/string.cpp +++ b/LibC/string.cpp @@ -6,7 +6,7 @@ extern "C" { void* memset(void* dest, int c, size_t n) { - byte* bdest = (byte*)dest; + uint8_t* bdest = (uint8_t*)dest; for (; n; --n) *(bdest++) = c; return dest; @@ -57,8 +57,8 @@ int strcmp(const char* s1, const char* s2) int memcmp(const void* v1, const void* v2, size_t n) { - auto* s1 = (const byte*)v1; - auto* s2 = (const byte*)v2; + auto* s1 = (const uint8_t*)v1; + auto* s2 = (const uint8_t*)v2; while (n-- > 0) { if (*s1++ != *s2++) return s1[-1] < s2[-1] ? -1 : 1; diff --git a/LibC/sys/cdefs.h b/LibC/sys/cdefs.h index 22c1525bf3e37574d099ca0b5ea377717322e5c5..a04364c61a71a80203c3ff8ac0d5e9729e5e6ae0 100644 --- a/LibC/sys/cdefs.h +++ b/LibC/sys/cdefs.h @@ -1,5 +1,7 @@ #pragma once +#define _POSIX_VERSION 200809L + #define ALWAYS_INLINE inline __attribute__ ((always_inline)) #define __NORETURN __attribute__ ((noreturn)) diff --git a/LibC/sys/param.h b/LibC/sys/param.h index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..bbc45173803a1a94b34545ed2ccd03600a2b63fa 100644 --- a/LibC/sys/param.h +++ b/LibC/sys/param.h @@ -0,0 +1,4 @@ +#pragma once + +#include + diff --git a/LibC/sys/times.h b/LibC/sys/times.h new file mode 100644 index 0000000000000000000000000000000000000000..dcda0d5a630a3199cbd1acb870888878a7cd3538 --- /dev/null +++ b/LibC/sys/times.h @@ -0,0 +1,17 @@ +#pragma once + +#include +#include + +__BEGIN_DECLS + +struct tms { + clock_t tms_utime; + clock_t tms_stime; + clock_t tms_cutime; + clock_t tms_cstime; +}; + +clock_t times(struct tms*); + +__END_DECLS diff --git a/LibC/sys/types.h b/LibC/sys/types.h index 919e41995464da7c1e1340d732453c7d95204411..425b8b333fb2a2f9f2d350e39ebabf4c885d71e2 100644 --- a/LibC/sys/types.h +++ b/LibC/sys/types.h @@ -1,34 +1,29 @@ #pragma once #include +#include __BEGIN_DECLS -typedef unsigned int dword; -typedef unsigned short word; -typedef unsigned char byte; - -typedef signed int signed_dword; -typedef signed short signed_word; -typedef signed char signed_byte; - -typedef dword uid_t; -typedef dword gid_t; +typedef uint32_t uid_t; +typedef uint32_t gid_t; typedef int pid_t; -typedef dword size_t; -typedef signed_dword ssize_t; +typedef uint32_t size_t; +typedef int32_t ssize_t; + +typedef uint32_t ino_t; +typedef int32_t off_t; -typedef dword ino_t; -typedef signed_dword off_t; +typedef uint32_t dev_t; +typedef uint32_t mode_t; +typedef uint32_t nlink_t; +typedef uint32_t blksize_t; +typedef uint32_t blkcnt_t; +typedef uint32_t time_t; +typedef uint32_t suseconds_t; -typedef dword dev_t; -typedef dword mode_t; -typedef dword nlink_t; -typedef dword blksize_t; -typedef dword blkcnt_t; -typedef dword time_t; -typedef dword suseconds_t; +typedef uint32_t clock_t; struct timeval { time_t tv_sec; diff --git a/LibC/time.cpp b/LibC/time.cpp index 43efb2f3645a52d7710cea4dc48eaac41f86d268..cc66535f62e93c00cca33255ab58ce5e88f375c3 100644 --- a/LibC/time.cpp +++ b/LibC/time.cpp @@ -6,13 +6,14 @@ extern "C" { time_t time(time_t* tloc) { - timeval tv; - if (gettimeofday(&tv) < 0) + struct timeval tv; + struct timezone tz; + if (gettimeofday(&tv, &tz) < 0) return (time_t)-1; return tv.tv_sec; } -int gettimeofday(timeval* tv) +int gettimeofday(struct timeval* tv, struct timezone*) { int rc = Syscall::invoke(Syscall::PosixGettimeofday, (dword)tv); __RETURN_WITH_ERRNO(rc, rc, -1); diff --git a/LibC/time.h b/LibC/time.h index dd1e20cf2d03c46105b2588d776d19de534c954a..c1b61b574a49e50fa9ca18954fb05ccddea1b085 100644 --- a/LibC/time.h +++ b/LibC/time.h @@ -5,7 +5,12 @@ __BEGIN_DECLS -int gettimeofday(timeval*); +typedef struct timezone { + int tz_minuteswest; + int tz_dsttime; +}; + +int gettimeofday(struct timeval*, struct timezone* tz); time_t time(time_t*); __END_DECLS diff --git a/LibC/times.cpp b/LibC/times.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a517e4385ef44deaec73a49325682cc06111c818 --- /dev/null +++ b/LibC/times.cpp @@ -0,0 +1,8 @@ +#include +#include + +clock_t times(struct tms*) +{ + assert(false); + return 0; +} diff --git a/LibC/unistd.cpp b/LibC/unistd.cpp index 7d1b65f1af2d8569473023dd04936b5e0a8d9b6c..5ff678d561f2f669f13feaac4f8103e19eaee0e8 100644 --- a/LibC/unistd.cpp +++ b/LibC/unistd.cpp @@ -1,6 +1,8 @@ -#include "unistd.h" -#include "string.h" -#include "errno.h" +#include +#include +#include +#include +#include #include extern "C" { @@ -78,9 +80,12 @@ pid_t getpgrp() __RETURN_WITH_ERRNO(rc, rc, -1); } -int open(const char* path, int options) +int open(const char* path, int options, ...) { - int rc = Syscall::invoke(Syscall::PosixOpen, (dword)path, (dword)options); + va_list ap; + va_start(ap, options); + int rc = Syscall::invoke(Syscall::PosixOpen, (dword)path, (dword)options, (dword)ap); + va_end(ap); __RETURN_WITH_ERRNO(rc, rc, -1); } @@ -169,5 +174,15 @@ off_t lseek(int fd, off_t offset, int whence) __RETURN_WITH_ERRNO(rc, rc, -1); } +int link(const char*, const char*) +{ + assert(false); +} + +int unlink(const char*) +{ + assert(false); +} + } diff --git a/LibC/unistd.h b/LibC/unistd.h index f304c555fc54b08470a1dad1e956c76376e116a2..7d4eebbbdb7fa47b700c46d62e7d979f78abda4e 100644 --- a/LibC/unistd.h +++ b/LibC/unistd.h @@ -22,7 +22,7 @@ gid_t getgid(); pid_t getpid(); pid_t tcgetpgrp(int fd); int tcsetpgrp(int fd, pid_t pgid); -int open(const char* path, int options); +int open(const char* path, int options, ...); ssize_t read(int fd, void* buf, size_t count); ssize_t write(int fd, const void* buf, size_t count); int close(int fd); @@ -37,6 +37,8 @@ ssize_t readlink(const char* path, char* buffer, size_t); char* ttyname(int fd); int ttyname_r(int fd, char* buffer, size_t); off_t lseek(int fd, off_t, int whence); +int link(const char* oldpath, const char* newpath); +int unlink(const char* pathname); #define WEXITSTATUS(status) (((status) & 0xff00) >> 8) #define WTERMSIG(status) ((status) & 0x7f) @@ -83,6 +85,12 @@ off_t lseek(int fd, off_t, int whence); #define O_RDONLY 0 #define O_WRONLY 1 #define O_RDWR 2 +#define O_CREAT 0100 +#define O_EXCL 0200 +#define O_NOCTTY 0400 +#define O_TRUNC 01000 +#define O_APPEND 02000 +#define O_NONBLOCK 04000 #define O_DIRECTORY 00200000 #define O_NOFOLLOW 00400000