Skip to content

Commit

Permalink
Miscellaneous compat work while seeing if GNU coreutils would build.
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomekling committed Nov 7, 2018
1 parent a7f1d89 commit d7a4157
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ WARNING_FLAGS = -Wextra -Wall -Wundef -Wcast-qual -Wwrite-strings
FLAVOR_FLAGS = -mregparm=3 -march=i386 -m32 -fno-exceptions -fno-rtti -fmerge-all-constants -fno-unroll-loops -fno-pie -fno-pic
OPTIMIZATION_FLAGS = -Os -fno-asynchronous-unwind-tables
INCLUDE_FLAGS = -I.. -I.
SUGGEST_FLAGS = -Wsuggest-attribute=pure -Wsuggest-attribute=const -Wsuggest-attribute=noreturn -Wsuggest-final-types -Wsuggest-final-methods -Wsuggest-override

DEFINES = -DSERENITY -DKERNEL -DSANITIZE_PTRS

CXXFLAGS = $(WARNING_FLAGS) $(OPTIMIZATION_FLAGS) $(KERNEL_FLAGS) $(FLAVOR_FLAGS) $(ARCH_FLAGS) $(STANDARD_FLAGS) $(INCLUDE_FLAGS) $(DEFINES)
CXXFLAGS = $(WARNING_FLAGS) $(OPTIMIZATION_FLAGS) $(KERNEL_FLAGS) $(FLAVOR_FLAGS) $(ARCH_FLAGS) $(STANDARD_FLAGS) $(SUGGEST_FLAGS) $(INCLUDE_FLAGS) $(DEFINES)
#CXX = /usr/local/gcc-4.8.1-for-linux64/bin/x86_64-pc-linux-g++
#LD = /usr/local/gcc-4.8.1-for-linux64/bin/x86_64-pc-linux-ld
CXX = g++-8
Expand Down
1 change: 1 addition & 0 deletions LibC/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ LIBC_OBJS = \
termcap.o \
setjmp.o \
stat.o \
mntent.o \
entry.o

OBJS = $(AK_OBJS) $(LIBC_OBJS)
Expand Down
2 changes: 2 additions & 0 deletions LibC/errno_numbers.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
__ERROR(ENAMETOOLONG, "Name too long") \
__ERROR(ELOOP, "Too many symlinks") \
__ERROR(EOVERFLOW, "Overflow") \
__ERROR(EOPNOTSUPP, "Operation not supported") \
__ERROR(ENOSYS, "No such syscall") \
__ERROR(ENOTIMPL, "Not implemented") \

enum __errno_values {
Expand Down
5 changes: 5 additions & 0 deletions LibC/limits.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#pragma once

#include <stdint.h>

#define PATH_MAX 4096

#define INT_MAX INT32_MAX
#define INT_MIN INT32_MIN
13 changes: 13 additions & 0 deletions LibC/mntent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <mntent.h>
#include <assert.h>

extern "C" {

struct mntent* getmntent(FILE* stream)
{
assert(false);
return nullptr;
}

}

23 changes: 23 additions & 0 deletions LibC/mntent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include <sys/cdefs.h>
#include <stdio.h>

__BEGIN_DECLS

#define MOUNTED "/etc/mtab"
#define MNTTAB "/etc/fstab"

struct mntent {
char* mnt_fsname;
char* mnt_dir;
char* mnt_type;
char* mnt_opts;
int mnt_freq;
int mnt_passno;
};

struct mntent* getmntent(FILE* stream);

__END_DECLS

4 changes: 4 additions & 0 deletions LibC/stddef.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once

#include <sys/cdefs.h>
#include <sys/types.h>
10 changes: 10 additions & 0 deletions LibC/stdint.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,15 @@ typedef signed int int32_t;
typedef signed short int16_t;
typedef signed char int8_t;

#define INT8_MIN (-128)
#define INT16_MIN (-32767-1)
#define INT32_MIN (-2147483647-1)
#define INT8_MAX (127)
#define INT16_MAX (32767)
#define INT32_MAX (2147483647)
#define UINT8_MAX (255)
#define UINT16_MAX (65535)
#define UINT32_MAX (4294967295U)

__END_DECLS

25 changes: 25 additions & 0 deletions LibC/stdio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ int fputc(int ch, FILE* stream)
{
assert(stream);
write(stream->fd, &ch, 1);
if (stream->eof)
return EOF;
return (byte)ch;
}

Expand All @@ -85,10 +87,31 @@ int putchar(int ch)
return putc(ch, stdout);
}

int fputs(const char* s, FILE* stream)
{
for (; *s; ++s) {
int rc = putc(*s, stream);
if (rc == EOF)
return EOF;
}
return putc('\n', stream);
}

int puts(const char* s)
{
fputs(s, stdout);
}

void clearerr(FILE* stream)
{
assert(stream);
stream->eof = false;
stream->error = false;
}

int ferror(FILE* stream)
{
return stream->error;
}

size_t fread(void* ptr, size_t size, size_t nmemb, FILE* stream)
Expand Down Expand Up @@ -190,6 +213,7 @@ FILE* fopen(const char* pathname, const char* mode)
auto* fp = (FILE*)malloc(sizeof(FILE));
fp->fd = fd;
fp->eof = false;
fp->error = 0;
return fp;
}

Expand All @@ -201,6 +225,7 @@ FILE* fdopen(int fd, const char* mode)
auto* fp = (FILE*)malloc(sizeof(FILE));
fp->fd = fd;
fp->eof = false;
fp->error = 0;
return fp;
}

Expand Down
5 changes: 5 additions & 0 deletions LibC/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ __BEGIN_DECLS
struct __STDIO_FILE {
int fd;
int eof;
int error;
};

typedef struct __STDIO_FILE FILE;
Expand All @@ -34,6 +35,7 @@ FILE* fopen(const char* pathname, const char* mode);
int fclose(FILE*);
void rewind(FILE*);
void clearerr(FILE*);
int ferror(FILE*);
int feof(FILE*);
int fflush(FILE*);
size_t fread(void* ptr, size_t size, size_t nmemb, FILE*);
Expand All @@ -42,6 +44,9 @@ int fprintf(FILE*, const char* fmt, ...);
int printf(const char* fmt, ...);
int sprintf(char* buffer, const char* fmt, ...);
int putchar(int ch);
int putc(int ch, FILE*);
int puts(const char*);
int fputs(const char*, FILE*);
void perror(const char*);
int sscanf (const char* buf, const char* fmt, ...);
int fscanf(FILE*, const char* fmt, ...);
Expand Down
1 change: 1 addition & 0 deletions LibC/sys/stat.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
__BEGIN_DECLS

mode_t umask(mode_t);
int chmod(const char* pathname, mode_t);

__END_DECLS
2 changes: 1 addition & 1 deletion LibC/sys/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ 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;
typedef uint32_t socklen_t;

struct timeval {
time_t tv_sec;
Expand Down

0 comments on commit d7a4157

Please sign in to comment.