diff options
author | Andreas Kling <awesomekling@gmail.com> | 2018-10-31 02:09:11 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2018-10-31 02:09:11 +0100 |
commit | bb90c8ecabd42d44094d1ce783ea8a9e346695bc (patch) | |
tree | 56074025556fb38c724cf897b195f514ed1636a0 /LibC | |
parent | 511ed4c4de349dd62dc302c9d46603aaeaf19f3d (diff) | |
download | serenity-bb90c8ecabd42d44094d1ce783ea8a9e346695bc.zip |
A bunch of LibC boilerplate stuff added while trying to get figlet to build.
Diffstat (limited to 'LibC')
-rw-r--r-- | LibC/Makefile | 2 | ||||
-rw-r--r-- | LibC/assert.h | 6 | ||||
-rw-r--r-- | LibC/ctype.h | 4 | ||||
-rw-r--r-- | LibC/dirent.h | 7 | ||||
-rw-r--r-- | LibC/entry.cpp | 15 | ||||
-rw-r--r-- | LibC/errno.h | 5 | ||||
-rw-r--r-- | LibC/fcntl.h | 0 | ||||
-rw-r--r-- | LibC/mman.h | 8 | ||||
-rw-r--r-- | LibC/process.h | 6 | ||||
-rw-r--r-- | LibC/signal.h | 6 | ||||
-rw-r--r-- | LibC/stdarg.h | 6 | ||||
-rw-r--r-- | LibC/stdio.cpp | 12 | ||||
-rw-r--r-- | LibC/stdio.h | 21 | ||||
-rw-r--r-- | LibC/stdlib.h | 7 | ||||
-rw-r--r-- | LibC/string.h | 7 | ||||
-rw-r--r-- | LibC/sys/cdefs.h | 10 | ||||
-rw-r--r-- | LibC/sys/ioctl.h | 0 | ||||
-rw-r--r-- | LibC/sys/stat.h | 0 | ||||
-rw-r--r-- | LibC/sys/types.h (renamed from LibC/types.h) | 12 | ||||
-rw-r--r-- | LibC/time.h | 7 | ||||
-rw-r--r-- | LibC/unistd.h | 10 | ||||
-rw-r--r-- | LibC/utsname.h | 7 |
22 files changed, 115 insertions, 43 deletions
diff --git a/LibC/Makefile b/LibC/Makefile index 15f5b33b7a..88ab201b63 100644 --- a/LibC/Makefile +++ b/LibC/Makefile @@ -23,7 +23,7 @@ OBJS = $(AK_OBJS) $(LIBC_OBJS) LIBRARY = LibC.a ARCH_FLAGS = -STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib +STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib -nostdinc LIBC_FLAGS = -ffreestanding -fno-stack-protector -fno-ident WARNING_FLAGS = -Wextra -Wall -Wundef -Wcast-qual -Wwrite-strings FLAVOR_FLAGS = -fomit-frame-pointer -mregparm=3 -march=i386 -m32 -fno-exceptions -fno-rtti -ffunction-sections -fdata-sections -fmerge-all-constants -fno-unroll-loops -falign-functions=1 -falign-jumps=1 -falign-loops=1 -fno-pie -fno-pic diff --git a/LibC/assert.h b/LibC/assert.h index 1f5610dd2e..b56bd14d79 100644 --- a/LibC/assert.h +++ b/LibC/assert.h @@ -1,6 +1,8 @@ #pragma once -extern "C" { +#include <sys/cdefs.h> + +__BEGIN_DECLS void __assertion_failed(const char* msg, const char* file, unsigned line, const char* func); @@ -10,5 +12,5 @@ void __assertion_failed(const char* msg, const char* file, unsigned line, const #define RELEASE_ASSERT assert #define ASSERT_NOT_REACHED() assert(false) -} +__END_DECLS diff --git a/LibC/ctype.h b/LibC/ctype.h new file mode 100644 index 0000000000..a69bbfdea9 --- /dev/null +++ b/LibC/ctype.h @@ -0,0 +1,4 @@ +#pragma once + +#define isascii(c) (((c) & ~0x7f) == 0) + diff --git a/LibC/dirent.h b/LibC/dirent.h index be069d8133..f8a832ae79 100644 --- a/LibC/dirent.h +++ b/LibC/dirent.h @@ -1,8 +1,9 @@ #pragma once -#include "types.h" +#include <sys/cdefs.h> +#include <sys/types.h> -extern "C" { +__BEGIN_DECLS struct dirent { ino_t d_ino; @@ -23,5 +24,5 @@ struct DIR { DIR* opendir(const char* name); dirent* readdir(DIR* dirp); -} +__END_DECLS diff --git a/LibC/entry.cpp b/LibC/entry.cpp index c3657b704b..e4ea51f9bd 100644 --- a/LibC/entry.cpp +++ b/LibC/entry.cpp @@ -1,14 +1,29 @@ +#include <stdio.h> #include <Kernel/Syscall.h> #include <AK/StringImpl.h> extern "C" int main(int, char**); +FILE __default_streams[3]; + int errno; +FILE* stdin; +FILE* stdout; +FILE* stderr; extern "C" int _start() { errno = 0; + __default_streams[0].fd = 0; + stdin = &__default_streams[0]; + + __default_streams[1].fd = 1; + stdout = &__default_streams[1]; + + __default_streams[2].fd = 2; + stderr = &__default_streams[2]; + StringImpl::initializeGlobals(); int argc; diff --git a/LibC/errno.h b/LibC/errno.h index c28cb71f24..235a9b383f 100644 --- a/LibC/errno.h +++ b/LibC/errno.h @@ -1,5 +1,6 @@ #pragma once +#include <sys/cdefs.h> #include <Kernel/errno.h> #define __RETURN_WITH_ERRNO(rc, good_ret, bad_ret) \ @@ -13,9 +14,9 @@ } \ } while(0) -extern "C" { +__BEGIN_DECLS extern int errno; -}; +__END_DECLS diff --git a/LibC/fcntl.h b/LibC/fcntl.h new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/LibC/fcntl.h diff --git a/LibC/mman.h b/LibC/mman.h index 5c82eef3ef..b587934043 100644 --- a/LibC/mman.h +++ b/LibC/mman.h @@ -1,11 +1,13 @@ #pragma once -#include "types.h" +#include <sys/cdefs.h> +#include <sys/types.h> -extern "C" { +__BEGIN_DECLS void* mmap(void*, size_t); int munmap(void*, size_t); int set_mmap_name(void*, size_t, const char*); -} +__END_DECLS + diff --git a/LibC/process.h b/LibC/process.h index 235415469a..9b5bf828a9 100644 --- a/LibC/process.h +++ b/LibC/process.h @@ -1,8 +1,10 @@ #pragma once -extern "C" { +#include <sys/cdefs.h> + +__BEGIN_DECLS int spawn(const char* path, const char** args); -} +__END_DECLS diff --git a/LibC/signal.h b/LibC/signal.h index 6a138098b6..73e7eeaa43 100644 --- a/LibC/signal.h +++ b/LibC/signal.h @@ -1,8 +1,8 @@ #pragma once -#include "types.h" +#include <sys/types.h> -extern "C" { +__BEGIN_DECLS int kill(pid_t, int sig); @@ -22,5 +22,5 @@ int kill(pid_t, int sig); #define SIGALRM 14 #define SIGTERM 15 -} +__END_DECLS diff --git a/LibC/stdarg.h b/LibC/stdarg.h index cf3d55977b..724ffb59d5 100644 --- a/LibC/stdarg.h +++ b/LibC/stdarg.h @@ -1,6 +1,8 @@ #pragma once -extern "C" { +#include <sys/cdefs.h> + +__BEGIN_DECLS typedef char* va_list; @@ -8,5 +10,5 @@ typedef char* va_list; #define va_arg(ap, t) ((t*)(ap += sizeof(t)))[-1] #define va_end(ap) ap = nullptr -} +__END_DECLS diff --git a/LibC/stdio.cpp b/LibC/stdio.cpp index e5488742db..af36176079 100644 --- a/LibC/stdio.cpp +++ b/LibC/stdio.cpp @@ -1,9 +1,9 @@ -#include "stdio.h" -#include "stdarg.h" -#include "types.h" -#include "string.h" -#include "errno.h" -#include "unistd.h" +#include <stdio.h> +#include <stdarg.h> +#include <sys/types.h> +#include <string.h> +#include <errno.h> +#include <unistd.h> #include <Kernel/Syscall.h> #include <AK/printf.cpp> diff --git a/LibC/stdio.h b/LibC/stdio.h index 1e6a79ea71..6129ccd3da 100644 --- a/LibC/stdio.h +++ b/LibC/stdio.h @@ -1,11 +1,28 @@ #pragma once -extern "C" { +#include <sys/cdefs.h> +__BEGIN_DECLS + +#ifndef EOF +#define EOF (-1) +#endif + +struct __STDIO_FILE { + int fd; +}; + +typedef struct __STDIO_FILE FILE; + +extern FILE* stdin; +extern FILE* stdout; +extern FILE* stderr; + +int fprintf(FILE*, const char* fmt, ...); int printf(const char* fmt, ...); int sprintf(char* buffer, const char* fmt, ...); int putchar(int ch); void perror(const char*); -} +__END_DECLS diff --git a/LibC/stdlib.h b/LibC/stdlib.h index 4ebff011da..0f88c6edf4 100644 --- a/LibC/stdlib.h +++ b/LibC/stdlib.h @@ -1,8 +1,9 @@ #pragma once -#include "types.h" +#include <sys/cdefs.h> +#include <sys/types.h> -extern "C" { +__BEGIN_DECLS void* malloc(size_t); void free(void*); @@ -12,5 +13,5 @@ void* realloc(void *ptr, size_t); void exit(int status); void abort(); -} +__END_DECLS diff --git a/LibC/string.h b/LibC/string.h index 6ef56e075b..42e3678293 100644 --- a/LibC/string.h +++ b/LibC/string.h @@ -1,8 +1,9 @@ #pragma once -#include "types.h" +#include <sys/cdefs.h> +#include <sys/types.h> -extern "C" { +__BEGIN_DECLS size_t strlen(const char*); int strcmp(const char*, const char*); @@ -10,5 +11,5 @@ int memcmp(const void*, const void*, size_t); void memcpy(void*, const void*, size_t); const char* strerror(int errnum); -} +__END_DECLS diff --git a/LibC/sys/cdefs.h b/LibC/sys/cdefs.h new file mode 100644 index 0000000000..c2285b88a8 --- /dev/null +++ b/LibC/sys/cdefs.h @@ -0,0 +1,10 @@ +#pragma once + +#ifdef __cplusplus +#define __BEGIN_DECLS extern "C" { +#define __END_DECLS } +#else +#define __BEGIN_DECLS +#define __END_DECLS +#endif + diff --git a/LibC/sys/ioctl.h b/LibC/sys/ioctl.h new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/LibC/sys/ioctl.h diff --git a/LibC/sys/stat.h b/LibC/sys/stat.h new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/LibC/sys/stat.h diff --git a/LibC/types.h b/LibC/sys/types.h index d8aacd8728..919e419954 100644 --- a/LibC/types.h +++ b/LibC/sys/types.h @@ -1,6 +1,8 @@ #pragma once -extern "C" { +#include <sys/cdefs.h> + +__BEGIN_DECLS typedef unsigned int dword; typedef unsigned short word; @@ -49,5 +51,11 @@ struct stat { time_t st_ctime; /* time of last status change */ }; -} +#ifdef __cplusplus +#define NULL nullptr +#else +#define NULL 0 +#endif + +__END_DECLS diff --git a/LibC/time.h b/LibC/time.h index acce4816bd..dd1e20cf2d 100644 --- a/LibC/time.h +++ b/LibC/time.h @@ -1,11 +1,12 @@ #pragma once -#include "types.h" +#include <sys/cdefs.h> +#include <sys/types.h> -extern "C" { +__BEGIN_DECLS int gettimeofday(timeval*); time_t time(time_t*); -} +__END_DECLS diff --git a/LibC/unistd.h b/LibC/unistd.h index 25ac8e0586..b0397c6aa9 100644 --- a/LibC/unistd.h +++ b/LibC/unistd.h @@ -1,8 +1,9 @@ #pragma once -#include "types.h" +#include <sys/cdefs.h> +#include <sys/types.h> -extern "C" { +__BEGIN_DECLS uid_t getuid(); gid_t getgid(); @@ -14,7 +15,7 @@ int close(int fd); pid_t waitpid(pid_t, int* wstatus, int options); int chdir(const char* path); char* getcwd(char* buffer, size_t size); -int lstat(const char* path, stat* statbuf); +int lstat(const char* path, struct stat* statbuf); int sleep(unsigned seconds); int gethostname(char*, size_t); ssize_t readlink(const char* path, char* buffer, size_t); @@ -62,4 +63,5 @@ int ttyname_r(int fd, char* buffer, size_t); #define O_DIRECTORY 00200000 #define O_NOFOLLOW 00400000 -} +__END_DECLS + diff --git a/LibC/utsname.h b/LibC/utsname.h index d50a5a4270..e617b2e34d 100644 --- a/LibC/utsname.h +++ b/LibC/utsname.h @@ -1,8 +1,10 @@ #pragma once +#include <sys/cdefs.h> + #define UTSNAME_ENTRY_LEN 65 -extern "C" { +__BEGIN_DECLS struct utsname { char sysname[UTSNAME_ENTRY_LEN]; @@ -14,4 +16,5 @@ struct utsname { int uname(struct utsname*); -} +__END_DECLS + |