1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:57:35 +00:00

Lots of minor compat stuff while seeing if bash would build.

We're quite far from bash building, but we'll get there eventually!
This commit is contained in:
Andreas Kling 2018-11-05 16:40:48 +01:00
parent e4611248c4
commit e76312ab63
21 changed files with 172 additions and 38 deletions

View file

@ -20,6 +20,7 @@ LIBC_OBJS = \
getopt.o \ getopt.o \
scanf.o \ scanf.o \
pwd.o \ pwd.o \
times.o \
entry.o entry.o
OBJS = $(AK_OBJS) $(LIBC_OBJS) OBJS = $(AK_OBJS) $(LIBC_OBJS)

11
LibC/endian.h Normal file
View file

@ -0,0 +1,11 @@
#pragma once
#include <sys/cdefs.h>
__BEGIN_DECLS
#define LITTLE_ENDIAN 1234
#define BIG_ENDIAN 4321
#define BYTE_ORDER LITTLE_ENDIAN
__END_DECLS

View file

@ -0,0 +1,13 @@
#pragma once
#include <sys/cdefs.h>
__BEGIN_DECLS
#define F_DUPFD 0
#define F_GETFD 1
#define F_SETFD 2
#define F_GETFL 3
#define F_SETFL 4
__END_DECLS

View file

@ -189,7 +189,7 @@ static int vsscanf(const char *buf, const char *s, va_list ap)
for (tc = s; isdigit(*s); s++); for (tc = s; isdigit(*s); s++);
strncpy (tmp, tc, s - tc); strncpy (tmp, tc, s - tc);
tmp[s - tc] = '\0'; tmp[s - tc] = '\0';
atob ((dword*)&width, tmp, 10); atob ((uint32_t*)&width, tmp, 10);
s--; s--;
} }
} }
@ -232,7 +232,7 @@ static int vsscanf(const char *buf, const char *s, va_list ap)
tmp[width] = '\0'; tmp[width] = '\0';
buf += width; buf += width;
if (!noassign) if (!noassign)
atob(va_arg(ap, dword*), tmp, base); atob(va_arg(ap, uint32_t*), tmp, base);
} }
if (!noassign) if (!noassign)
++count; ++count;

0
LibC/setjmp.cpp Normal file
View file

View file

@ -0,0 +1,13 @@
#pragma once
#include <sys/cdefs.h>
#include <sys/types.h>
__BEGIN_DECLS
typedef uint32_t jmp_buf[6];
int setjmp(jmp_buf);
void longjmp(jmp_buf, int val);
__END_DECLS

View file

@ -1,5 +1,6 @@
#include "unistd.h" #include <unistd.h>
#include "errno.h" #include <errno.h>
#include <signal.h>
#include <Kernel/Syscall.h> #include <Kernel/Syscall.h>
extern "C" { extern "C" {

View file

@ -4,8 +4,31 @@
__BEGIN_DECLS __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); 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 SIGHUP 1
#define SIGINT 2 #define SIGINT 2
#define SIGQUIT 3 #define SIGQUIT 3

0
LibC/stddef.h Normal file
View file

16
LibC/stdint.h Normal file
View file

@ -0,0 +1,16 @@
#pragma once
#include <sys/cdefs.h>
__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

View file

@ -43,6 +43,7 @@ int sprintf(char* buffer, const char* fmt, ...);
int putchar(int ch); int putchar(int ch);
void perror(const char*); void perror(const char*);
int sscanf (const char* buf, const char* fmt, ...); int sscanf (const char* buf, const char* fmt, ...);
int fscanf(FILE*, const char* fmt, ...);
__END_DECLS __END_DECLS

View file

@ -6,7 +6,7 @@ extern "C" {
void* memset(void* dest, int c, size_t n) void* memset(void* dest, int c, size_t n)
{ {
byte* bdest = (byte*)dest; uint8_t* bdest = (uint8_t*)dest;
for (; n; --n) for (; n; --n)
*(bdest++) = c; *(bdest++) = c;
return dest; 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) int memcmp(const void* v1, const void* v2, size_t n)
{ {
auto* s1 = (const byte*)v1; auto* s1 = (const uint8_t*)v1;
auto* s2 = (const byte*)v2; auto* s2 = (const uint8_t*)v2;
while (n-- > 0) { while (n-- > 0) {
if (*s1++ != *s2++) if (*s1++ != *s2++)
return s1[-1] < s2[-1] ? -1 : 1; return s1[-1] < s2[-1] ? -1 : 1;

View file

@ -1,5 +1,7 @@
#pragma once #pragma once
#define _POSIX_VERSION 200809L
#define ALWAYS_INLINE inline __attribute__ ((always_inline)) #define ALWAYS_INLINE inline __attribute__ ((always_inline))
#define __NORETURN __attribute__ ((noreturn)) #define __NORETURN __attribute__ ((noreturn))

View file

@ -0,0 +1,4 @@
#pragma once
#include <endian.h>

17
LibC/sys/times.h Normal file
View file

@ -0,0 +1,17 @@
#pragma once
#include <sys/cdefs.h>
#include <sys/types.h>
__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

View file

@ -1,34 +1,29 @@
#pragma once #pragma once
#include <sys/cdefs.h> #include <sys/cdefs.h>
#include <stdint.h>
__BEGIN_DECLS __BEGIN_DECLS
typedef unsigned int dword; typedef uint32_t uid_t;
typedef unsigned short word; typedef uint32_t gid_t;
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 int pid_t; typedef int pid_t;
typedef dword size_t; typedef uint32_t size_t;
typedef signed_dword ssize_t; typedef int32_t ssize_t;
typedef dword ino_t; typedef uint32_t ino_t;
typedef signed_dword off_t; typedef int32_t off_t;
typedef dword dev_t; typedef uint32_t dev_t;
typedef dword mode_t; typedef uint32_t mode_t;
typedef dword nlink_t; typedef uint32_t nlink_t;
typedef dword blksize_t; typedef uint32_t blksize_t;
typedef dword blkcnt_t; typedef uint32_t blkcnt_t;
typedef dword time_t; typedef uint32_t time_t;
typedef dword suseconds_t; typedef uint32_t suseconds_t;
typedef uint32_t clock_t;
struct timeval { struct timeval {
time_t tv_sec; time_t tv_sec;

View file

@ -6,13 +6,14 @@ extern "C" {
time_t time(time_t* tloc) time_t time(time_t* tloc)
{ {
timeval tv; struct timeval tv;
if (gettimeofday(&tv) < 0) struct timezone tz;
if (gettimeofday(&tv, &tz) < 0)
return (time_t)-1; return (time_t)-1;
return tv.tv_sec; return tv.tv_sec;
} }
int gettimeofday(timeval* tv) int gettimeofday(struct timeval* tv, struct timezone*)
{ {
int rc = Syscall::invoke(Syscall::PosixGettimeofday, (dword)tv); int rc = Syscall::invoke(Syscall::PosixGettimeofday, (dword)tv);
__RETURN_WITH_ERRNO(rc, rc, -1); __RETURN_WITH_ERRNO(rc, rc, -1);

View file

@ -5,7 +5,12 @@
__BEGIN_DECLS __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*); time_t time(time_t*);
__END_DECLS __END_DECLS

8
LibC/times.cpp Normal file
View file

@ -0,0 +1,8 @@
#include <sys/times.h>
#include <assert.h>
clock_t times(struct tms*)
{
assert(false);
return 0;
}

View file

@ -1,6 +1,8 @@
#include "unistd.h" #include <unistd.h>
#include "string.h" #include <string.h>
#include "errno.h" #include <errno.h>
#include <stdarg.h>
#include <assert.h>
#include <Kernel/Syscall.h> #include <Kernel/Syscall.h>
extern "C" { extern "C" {
@ -78,9 +80,12 @@ pid_t getpgrp()
__RETURN_WITH_ERRNO(rc, rc, -1); __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); __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); __RETURN_WITH_ERRNO(rc, rc, -1);
} }
int link(const char*, const char*)
{
assert(false);
}
int unlink(const char*)
{
assert(false);
}
} }

View file

@ -22,7 +22,7 @@ gid_t getgid();
pid_t getpid(); pid_t getpid();
pid_t tcgetpgrp(int fd); pid_t tcgetpgrp(int fd);
int tcsetpgrp(int fd, pid_t pgid); 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 read(int fd, void* buf, size_t count);
ssize_t write(int fd, const void* buf, size_t count); ssize_t write(int fd, const void* buf, size_t count);
int close(int fd); int close(int fd);
@ -37,6 +37,8 @@ ssize_t readlink(const char* path, char* buffer, size_t);
char* ttyname(int fd); char* ttyname(int fd);
int ttyname_r(int fd, char* buffer, size_t); int ttyname_r(int fd, char* buffer, size_t);
off_t lseek(int fd, off_t, int whence); 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 WEXITSTATUS(status) (((status) & 0xff00) >> 8)
#define WTERMSIG(status) ((status) & 0x7f) #define WTERMSIG(status) ((status) & 0x7f)
@ -83,6 +85,12 @@ off_t lseek(int fd, off_t, int whence);
#define O_RDONLY 0 #define O_RDONLY 0
#define O_WRONLY 1 #define O_WRONLY 1
#define O_RDWR 2 #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_DIRECTORY 00200000
#define O_NOFOLLOW 00400000 #define O_NOFOLLOW 00400000