diff --git a/LibC/Makefile b/LibC/Makefile index 39ff6620fb1..360a1ab65c0 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 00000000000..7bc4e074085 --- /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 e69de29bb2d..cf679753cba 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 23c673c71a7..b9b4726b7b9 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 00000000000..e69de29bb2d diff --git a/LibC/setjmp.h b/LibC/setjmp.h index e69de29bb2d..eef107ebb46 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 ab73f4a5e87..76442ed3ec6 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 73e7eeaa43a..0e36c40f194 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 00000000000..e69de29bb2d diff --git a/LibC/stdint.h b/LibC/stdint.h new file mode 100644 index 00000000000..7deb47e5da2 --- /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 c681f6ad185..8ad7074a39a 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 ebd632c70ba..c79ec1d0267 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 22c1525bf3e..a04364c61a7 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 e69de29bb2d..bbc45173803 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 00000000000..dcda0d5a630 --- /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 919e4199546..425b8b333fb 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 dword ino_t; -typedef signed_dword off_t; +typedef uint32_t ino_t; +typedef int32_t off_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 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 uint32_t clock_t; struct timeval { time_t tv_sec; diff --git a/LibC/time.cpp b/LibC/time.cpp index 43efb2f3645..cc66535f62e 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 dd1e20cf2d0..c1b61b574a4 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 00000000000..a517e4385ef --- /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 7d1b65f1af2..5ff678d561f 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 f304c555fc5..7d4eebbbdb7 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