From 77084a03c17e4906aaf603f0189d3e408ee4e184 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 1 Sep 2012 14:38:42 +0800 Subject: [PATCH] Usermode/libc - Adding features --- Usermode/Libraries/libc.so_src/Makefile | 1 + Usermode/Libraries/libc.so_src/fileIO.c | 19 +++++++++++++++++++ .../libc.so_src/include_exp/assert.h | 18 ++++++++++++++++++ .../Libraries/libc.so_src/include_exp/stdio.h | 5 +++++ Usermode/Libraries/libc.so_src/perror.c | 14 ++++++++++++++ Usermode/Libraries/libc.so_src/rules.mk | 1 + 6 files changed, 58 insertions(+) create mode 100644 Usermode/Libraries/libc.so_src/include_exp/assert.h create mode 100644 Usermode/Libraries/libc.so_src/perror.c diff --git a/Usermode/Libraries/libc.so_src/Makefile b/Usermode/Libraries/libc.so_src/Makefile index 61d127f7..6484897b 100644 --- a/Usermode/Libraries/libc.so_src/Makefile +++ b/Usermode/Libraries/libc.so_src/Makefile @@ -11,6 +11,7 @@ LDFLAGS += -soname libc.so -Map map.txt -lgcc INCFILES := stdio.h stdlib.h OBJ = stub.o heap.o stdlib.o env.o fileIO.o string.o select.o rand.o +OBJ += perror.o OBJ += arch/$(ARCHDIR).ao # signals.o DEPFILES := $(OBJ:%.o=%.d) diff --git a/Usermode/Libraries/libc.so_src/fileIO.c b/Usermode/Libraries/libc.so_src/fileIO.c index 776a2def..c0013c98 100644 --- a/Usermode/Libraries/libc.so_src/fileIO.c +++ b/Usermode/Libraries/libc.so_src/fileIO.c @@ -131,6 +131,25 @@ EXPORT void fflush(FILE *fp) ///\todo Implement } +EXPORT void clearerr(FILE *stream) +{ + /// \todo Impliment +} + +EXPORT int feof(FILE *stream) +{ + return 0; //stream->; // ? +} + +EXPORT int ferror(FILE *stream) +{ + return 0; +} +EXPORT int fileno(FILE *stream) +{ + return stream->FD; +} + EXPORT off_t ftell(FILE *fp) { if(!fp || !fp->FD) return -1; diff --git a/Usermode/Libraries/libc.so_src/include_exp/assert.h b/Usermode/Libraries/libc.so_src/include_exp/assert.h new file mode 100644 index 00000000..07b20b3a --- /dev/null +++ b/Usermode/Libraries/libc.so_src/include_exp/assert.h @@ -0,0 +1,18 @@ +/* + * Acess2 C Library + * - By John Hodge (thePowersGang) + * + * assert.h + * - assert(expr) + */ +#ifndef _LIBC__ASSERT_H_ +#define _LIBC__ASSERT_H_ + +#ifdef NDEBUG +# define assert(expr) do{}while(0) +#else +# define assert(expr) do{if(!(expr)) { fprintf(stderr, "%s:%i: Assertion '%s' failed\n", __FILE__, __LINE__, #expr); exit(-1);}}while(0) +#endif + +#endif + diff --git a/Usermode/Libraries/libc.so_src/include_exp/stdio.h b/Usermode/Libraries/libc.so_src/include_exp/stdio.h index be4f20aa..faf20f0e 100644 --- a/Usermode/Libraries/libc.so_src/include_exp/stdio.h +++ b/Usermode/Libraries/libc.so_src/include_exp/stdio.h @@ -21,6 +21,7 @@ extern int vsnprintf(char *buf, size_t __maxlen, const char *format, va_list arg extern int vsprintf(char *buf, const char *format, va_list args); extern int sprintf(char *buf, const char *format, ...); extern int snprintf(char *buf, size_t maxlen, const char *format, ...); +extern void perror(const char *s); extern FILE *fopen(const char *file, const char *mode); extern FILE *freopen(const char *file, const char *mode, FILE *fp); @@ -29,6 +30,10 @@ extern int fclose(FILE *fp); extern void fflush(FILE *fp); extern off_t ftell(FILE *fp); extern int fseek(FILE *fp, long int amt, int whence); +extern void clearerr(FILE *stream); +extern int feof(FILE *stream); +extern int ferror(FILE *stream); +extern int fileno(FILE *stream); extern size_t fread(void *buf, size_t size, size_t n, FILE *fp); extern size_t fwrite(void *buf, size_t size, size_t n, FILE *fp); diff --git a/Usermode/Libraries/libc.so_src/perror.c b/Usermode/Libraries/libc.so_src/perror.c new file mode 100644 index 00000000..0431635d --- /dev/null +++ b/Usermode/Libraries/libc.so_src/perror.c @@ -0,0 +1,14 @@ +/* + * Acess2 C Library + * - By John Hodge (thePowersGang) + * + * perror.c + * - perror() and friends + */ +#include +#include + +void perror(const char *s) +{ + fprintf(stderr, "%s: Error (%i)\n", s, errno); +} diff --git a/Usermode/Libraries/libc.so_src/rules.mk b/Usermode/Libraries/libc.so_src/rules.mk index f689f341..23f39258 100644 --- a/Usermode/Libraries/libc.so_src/rules.mk +++ b/Usermode/Libraries/libc.so_src/rules.mk @@ -4,6 +4,7 @@ include $(BASE)header.mk # Variables SRCS := stub.c heap.c stdlib.c env.c fileIO.c string.c select.c +SRCS += perror.c SRCS += arch/$(ARCHDIR).$(ASSUFFIX) # signals.c BIN := $(OUTPUTDIR)Libs/libc.so -- 2.20.1