diff options
author | Alex Auvolat <alex@adnab.me> | 2016-07-16 01:28:04 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2016-07-16 01:28:04 +0200 |
commit | 59000174aa50ed6b2d24a71576d15e6a53c5be0c (patch) | |
tree | 38e0a7623f1b83c4dabb1fddfc49014e623f6456 /src | |
parent | 32407e728971006ed3d0885e01c22fb66c8adc57 (diff) | |
download | kogata-59000174aa50ed6b2d24a71576d15e6a53c5be0c.tar.gz kogata-59000174aa50ed6b2d24a71576d15e6a53c5be0c.zip |
Add stubs for many libc functions, and a few implemenations too
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/bam.lua | 2 | ||||
-rw-r--r-- | src/common/include/kogata/slab_alloc.h | 1 | ||||
-rw-r--r-- | src/common/include/string.h | 7 | ||||
-rw-r--r-- | src/common/libc/ctype.c | 50 | ||||
-rw-r--r-- | src/common/libc/string.c | 48 | ||||
-rw-r--r-- | src/common/libkogata/slab_alloc.c | 57 | ||||
-rw-r--r-- | src/lib/bam.lua | 3 | ||||
-rw-r--r-- | src/lib/include/math.h | 41 | ||||
-rw-r--r-- | src/lib/include/setjmp.h | 6 | ||||
-rw-r--r-- | src/lib/include/signal.h | 6 | ||||
-rw-r--r-- | src/lib/include/stdio.h | 6 | ||||
-rw-r--r-- | src/lib/include/stdlib.h | 5 | ||||
-rw-r--r-- | src/lib/include/time.h | 25 | ||||
-rw-r--r-- | src/lib/libc/errno.c | 6 | ||||
-rw-r--r-- | src/lib/libc/locale.c | 22 | ||||
-rw-r--r-- | src/lib/libc/malloc.c | 4 | ||||
-rw-r--r-- | src/lib/libc/math.c | 151 | ||||
-rw-r--r-- | src/lib/libc/setjmp.s | 53 | ||||
-rw-r--r-- | src/lib/libc/signal.c | 8 | ||||
-rw-r--r-- | src/lib/libc/stdio.c | 152 | ||||
-rw-r--r-- | src/lib/libc/stdlib.c | 80 | ||||
-rw-r--r-- | src/lib/libc/time.c | 50 | ||||
-rw-r--r-- | src/lib/lua/luaconf.h | 2 |
23 files changed, 740 insertions, 45 deletions
diff --git a/src/bin/bam.lua b/src/bin/bam.lua index 4026bce..15cfb40 100644 --- a/src/bin/bam.lua +++ b/src/bin/bam.lua @@ -18,6 +18,6 @@ local function bin_exe(name, deps) end bin = { - -- bin_exe('lua', {liblua}), + bin_exe('lua', {liblua}), -- bin_exe('luac', {liblua}), } diff --git a/src/common/include/kogata/slab_alloc.h b/src/common/include/kogata/slab_alloc.h index 1191057..73b4e82 100644 --- a/src/common/include/kogata/slab_alloc.h +++ b/src/common/include/kogata/slab_alloc.h @@ -41,5 +41,6 @@ void destroy_slab_allocator(mem_allocator_t*); void* slab_alloc(mem_allocator_t* a, size_t sz); void slab_free(mem_allocator_t* a, void* ptr); +void* slab_realloc(mem_allocator_t* a, void* ptr, size_t sz); /* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/common/include/string.h b/src/common/include/string.h index d38bbb6..f13037b 100644 --- a/src/common/include/string.h +++ b/src/common/include/string.h @@ -20,13 +20,12 @@ int strncmp(const char *s1, const char *s2, size_t n); char *strdup(const char* str); char *strndup(const char* str, size_t count); -//TODO +void *memchr(const void *s, int c, size_t n); int strcoll(const char *s1, const char *s2); size_t strspn(const char *s, const char *accept); -char *strstr(const char *haystack, const char *needle); +const char *strstr(const char *haystack, const char *needle); char* strerror(int errnum); -char *strpbrk(const char *s, const char *accept); -void *memchr(const void *s, int c, size_t n); +const char *strpbrk(const char *s, const char *accept); /* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/common/libc/ctype.c b/src/common/libc/ctype.c index 56daa6b..e54a24c 100644 --- a/src/common/libc/ctype.c +++ b/src/common/libc/ctype.c @@ -1,3 +1,51 @@ #include <ctype.h> -// TODO + +int isalnum(int c) { + return isalpha(c) || isdigit(c); +} +int isalpha(int c) { + return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'); +} +int isdigit(int c) { + return (c >= '0' && c <= '9'); +} +int isxdigit(int c) { + return isdigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'); +} +int isspace(int c) { + return c == ' ' || c == '\t' || c == '\r' || c == '\n'; +} +int isprint(int c) { + return (c >= ' ' && c < 256) || isspace(c); +} +int isupper(int c) { + return c >= 'A' && c <= 'Z'; +} +int islower(int c) { + return c >= 'a' && c <= 'z'; +} +int ispunct(int c) { + return isprint(c) && !isspace(c); +} +int isgraph(int c) { + return c > ' ' && c < 256; +} +int iscntrl(int c) { + return c > 0 && c < ' '; +} + +int toupper(int c) { + if (islower(c)) + return c + 'A' - 'a'; + else + return c; +} +int tolower(int c) { + if (isupper(c)) + return c + 'a' - 'A'; + else + return c; +} + +/* vim: set sts=0 ts=4 sw=4 tw=0 noet :*/ diff --git a/src/common/libc/string.c b/src/common/libc/string.c index e1ed21e..4b99dda 100644 --- a/src/common/libc/string.c +++ b/src/common/libc/string.c @@ -1,3 +1,4 @@ +#include <stdbool.h> #include <string.h> #include <kogata/malloc.h> @@ -149,4 +150,51 @@ int strcoll(const char *s1, const char *s2) { return strcmp(s1, s2); } +void *memchr(const void *s, int c, size_t n) { + unsigned char *p = (unsigned char*)s; + for (size_t i = 0; i < n; i++) { + if (p[i] == (unsigned char)c) + return &p[i]; + } + return NULL; +} + +size_t strspn(const char *s, const char *accept) { + size_t l = 0; + while (s[l] != 0) { + bool ok = false; + for (const char* p = accept; *p != 0; p++) { + if (s[l] == *p) { + ok = true; + break; + } + } + if (!ok) break; + l++; + } + return l; +} + +const char *strstr(const char *haystack, const char *needle) { + for (const char* p = haystack; *p != 0; p++) { + if (!strcmp(p, needle)) return p; + } + return NULL; +} + +char* strerror(int errnum) { + // TODO + return "(unspecified error)"; +} + +const char *strpbrk(const char *s, const char *accept) { + while (*s) { + for (const char *p = accept; *p != 0; p++) { + if (*s == *p) return s; + } + s++; + } + return NULL; +} + /* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/common/libkogata/slab_alloc.c b/src/common/libkogata/slab_alloc.c index 6362207..1d56e6f 100644 --- a/src/common/libkogata/slab_alloc.c +++ b/src/common/libkogata/slab_alloc.c @@ -1,3 +1,5 @@ +#include <string.h> + #include <kogata/slab_alloc.h> typedef struct object { @@ -293,5 +295,60 @@ void slab_free(mem_allocator_t* a, void* addr) { } } +size_t slab_find_getsize(mem_allocator_t *a, void* addr) { + // look for block in caches + for (int i = 0; a->types[i].obj_size != 0; i++) { + size_t region_size = PAGE_SIZE * a->types[i].pages_per_cache; + for (cache_t *r = a->slabs[i].first_cache; r != 0; r = r->next_cache) { + if (addr >= r->region_addr && addr < r->region_addr + region_size) { + ASSERT((addr - r->region_addr) % a->types[i].obj_size == 0); + return a->types[i].obj_size; + } + } + } + + // otherwise the block was directly allocated : look for it in regions. + for (region_t *i = a->all_regions; i != 0; i = i->next_region) { + if (i->region_addr == addr) { + return i->region_size; + } + } + ASSERT(false); +} + +void* slab_realloc(mem_allocator_t* a, void* ptr, size_t sz) { + if (ptr == 0) return slab_alloc(a, sz); + if (sz == 0) { + slab_free(a, ptr); + return NULL; + } + + size_t old_sz = slab_find_getsize(a, ptr); + + // What size will be allocated ? + size_t new_sz = 0; + for (int i = 0; a->types[i].obj_size != 0; i++) { + const size_t obj_size = a->types[i].obj_size; + if (sz <= obj_size) { + new_sz = obj_size; + break; + } + } + if (new_sz == 0) new_sz = sz; + + // If the space is already big enough, do nothing + if (old_sz == new_sz) return ptr; + + // Reallocate + void* ptr2 = slab_alloc(a, sz); + if (ptr2 == NULL) return NULL; + + size_t min_sz = (old_sz < sz ? old_sz : sz); + memcpy(ptr2, ptr, min_sz); + slab_free(a, ptr); + + return ptr2; +} + /* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/lib/bam.lua b/src/lib/bam.lua index cef678e..44edad2 100644 --- a/src/lib/bam.lua +++ b/src/lib/bam.lua @@ -1,5 +1,6 @@ local function lib(name) - local source = Collect('src/lib/' .. name .. '/*.c') + local source = {Collect('src/lib/' .. name .. '/*.c'), + Collect('src/lib/' .. name .. '/*.s')} return Compile(user_settings, source) end diff --git a/src/lib/include/math.h b/src/lib/include/math.h index 64c46e7..4a23bd8 100644 --- a/src/lib/include/math.h +++ b/src/lib/include/math.h @@ -10,29 +10,50 @@ #define HUGE_VALF 0 #define HUGE_VALL 0 +// Float float fabsf(float x); - float cosf(float x); - float sinf(float x); - float tanf(float x); +float cosf(float x); +float sinf(float x); +float tanf(float x); - float acosf(float x); - float asinf(float x); +float acosf(float x); +float asinf(float x); float atan2f(float y, float x); float floorf(float x); float ceilf(float x); float fmodf(float x, float y); + float sqrtf(float x); float logf(float x); float log2f(float x); float log10f(float x); float expf(float x); float frexpf(float x, int *exp); - float powf(float x, float y); - - - - +float powf(float x, float y); + +// Double +double fabs(double x); + +double cos(double x); +double sin(double x); +double tan(double x); + +double acos(double x); +double asin(double x); +double atan2(double y, double x); + +double floor(double x); +double ceil(double x); +double fmod(double x, double y); + +double sqrt(double x); +double log(double x); +double log2(double x); +double log10(double x); +double exp(double x); +double frexp(double x, int *exp); +double pow(double x, double y); /* vim: set sts=0 ts=4 sw=4 tw=0 noet :*/ diff --git a/src/lib/include/setjmp.h b/src/lib/include/setjmp.h index 7fab8c3..42df49e 100644 --- a/src/lib/include/setjmp.h +++ b/src/lib/include/setjmp.h @@ -3,17 +3,13 @@ // TODO struct _jmp_buf { - // TODO - int a; + uint32_t stuff[10]; // 40 bytes }; typedef struct _jmp_buf jmp_buf; int setjmp(jmp_buf env); -//int sigsetjmp(sigjmp_buf env, int savesigs); void longjmp(jmp_buf env, int val); -//void siglongjmp(sigjmp_buf env, int val); - /* vim: set sts=0 ts=4 sw=4 tw=0 noet :*/ diff --git a/src/lib/include/signal.h b/src/lib/include/signal.h index 297db87..4b1b58f 100644 --- a/src/lib/include/signal.h +++ b/src/lib/include/signal.h @@ -1,8 +1,10 @@ #pragma once -// TODO +#include <stdatomic.h> + +typedef atomic_int sig_atomic_t; -typedef int sig_atomic_t; +// TODO #define SIG_DFL 0 // stupid diff --git a/src/lib/include/stdio.h b/src/lib/include/stdio.h index 1e75270..3914a89 100644 --- a/src/lib/include/stdio.h +++ b/src/lib/include/stdio.h @@ -38,7 +38,7 @@ int ferror(FILE *stream); int fileno(FILE *stream); -size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream); +size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream); size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream); int fflush(FILE* f); @@ -70,7 +70,7 @@ int fsetpos(FILE *stream, const fpos_t *pos); #define SEEK_CUR 1 #define SEEK_END 2 -#define L_tmpnam 12 +#define L_tmpnam 128 FILE *tmpfile(void); char *tmpnam(char *s); @@ -79,8 +79,6 @@ int remove(const char *pathname); - - int printf(const char *format, ...); int fprintf(FILE *stream, const char *format, ...); int dprintf(int fd, const char *format, ...); diff --git a/src/lib/include/stdlib.h b/src/lib/include/stdlib.h index 30da9a6..53aef80 100644 --- a/src/lib/include/stdlib.h +++ b/src/lib/include/stdlib.h @@ -14,9 +14,8 @@ void srand(unsigned int seed); void abort() __attribute__((__noreturn__)); -double strtod(const char *nptr, char **endptr); -float strtof(const char *nptr, char **endptr); -long double strtold(const char *nptr, char **endptr); +double strtod(const char *nptr, const char **endptr); +float strtof(const char *nptr, const char **endptr); char *getenv(const char *name); diff --git a/src/lib/include/time.h b/src/lib/include/time.h index 6529c9a..fe274bb 100644 --- a/src/lib/include/time.h +++ b/src/lib/include/time.h @@ -1,17 +1,20 @@ #pragma once +#include <stdint.h> +#include <stddef.h> + // TODO struct tm { - int tm_sec; // Seconds [0,60]. - int tm_min; // Minutes [0,59]. - int tm_hour; // Hour [0,23]. - int tm_mday; // Day of month [1,31]. - int tm_mon; // Month of year [0,11]. - int tm_year; // Years since 1900. - int tm_wday; // Day of week [0,6] (Sunday =0). - int tm_yday; // Day of year [0,365]. - int tm_isdst; // Daylight Savings flag. + int tm_sec; // Seconds [0,60]. + int tm_min; // Minutes [0,59]. + int tm_hour; // Hour [0,23]. + int tm_mday; // Day of month [1,31]. + int tm_mon; // Month of year [0,11]. + int tm_year; // Years since 1900. + int tm_wday; // Day of week [0,6] (Sunday =0). + int tm_yday; // Day of year [0,365]. + int tm_isdst; // Daylight Savings flag. }; typedef int64_t time_t; @@ -20,16 +23,12 @@ time_t time(time_t*); double difftime(time_t time1, time_t time0); char *asctime(const struct tm *tm); -char *asctime_r(const struct tm *tm, char *buf); char *ctime(const time_t *timep); -char *ctime_r(const time_t *timep, char *buf); struct tm *gmtime(const time_t *timep); -struct tm *gmtime_r(const time_t *timep, struct tm *result); struct tm *localtime(const time_t *timep); -struct tm *localtime_r(const time_t *timep, struct tm *result); time_t mktime(struct tm *tm); diff --git a/src/lib/libc/errno.c b/src/lib/libc/errno.c new file mode 100644 index 0000000..b5865fa --- /dev/null +++ b/src/lib/libc/errno.c @@ -0,0 +1,6 @@ +#include <errno.h> + +int errno = 0; + + +/* vim: set sts=0 ts=4 sw=4 tw=0 noet :*/ diff --git a/src/lib/libc/locale.c b/src/lib/libc/locale.c new file mode 100644 index 0000000..3c7db9e --- /dev/null +++ b/src/lib/libc/locale.c @@ -0,0 +1,22 @@ +#include <locale.h> +#include <stddef.h> +#include <limits.h> + +struct lconv c_locale_lconv = { + ".", "", "", "", "", "", "", "", + "", "", CHAR_MAX, CHAR_MAX, CHAR_MAX, + CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX, + CHAR_MAX +}; + +struct lconv *localeconv() { + // TODO + return &c_locale_lconv; +} + +char* setlocale(int catebory, const char* locale) { + // TODO + return NULL; +} + +/* vim: set sts=0 ts=4 sw=4 tw=0 noet :*/ diff --git a/src/lib/libc/malloc.c b/src/lib/libc/malloc.c index cb983fd..2d43656 100644 --- a/src/lib/libc/malloc.c +++ b/src/lib/libc/malloc.c @@ -63,6 +63,10 @@ void* calloc(size_t nmemb, size_t sz) { return r; } +void* realloc(void* ptr, size_t sz) { + return slab_realloc(mem_allocator, ptr, sz); +} + void free(void* ptr) { slab_free(mem_allocator, ptr); } diff --git a/src/lib/libc/math.c b/src/lib/libc/math.c new file mode 100644 index 0000000..b859f04 --- /dev/null +++ b/src/lib/libc/math.c @@ -0,0 +1,151 @@ +#include <math.h> + +float fabsf(float x) { + // TODO + return 0; +} + +float cosf(float x) { + // TODO + return 0; +} +float sinf(float x) { + // TODO + return 0; +} +float tanf(float x) { + // TODO + return 0; +} + +float acosf(float x) { + // TODO + return 0; +} +float asinf(float x) { + // TODO + return 0; +} +float atan2f(float y, float x) { + // TODO + return 0; +} + +float floorf(float x) { + // TODO + return 0; +} +float ceilf(float x) { + // TODO + return 0; +} +float fmodf(float x, float y) { + // TODO + return 0; +} + +float sqrtf(float x) { + // TODO + return 0; +} +float logf(float x) { + // TODO + return 0; +} +float log2f(float x) { + // TODO + return 0; +} +float log10f(float x) { + // TODO + return 0; +} +float expf(float x) { + // TODO + return 0; +} +float frexpf(float x, int *exp) { + // TODO + return 0; +} +float powf(float x, float y) { + // TODO + return 0; +} + + + +double fabs(double x) { + // TODO + return 0; +} + +double cos(double x) { + // TODO + return 0; +} +double sin(double x) { + // TODO + return 0; +} +double tan(double x) { + // TODO + return 0; +} + +double acos(double x) { + // TODO + return 0; +} +double asin(double x) { + // TODO + return 0; +} +double atan2(double y, double x) { + // TODO + return 0; +} + +double floor(double x) { + // TODO + return 0; +} +double ceil(double x) { + // TODO + return 0; +} +double fmod(double x, double y) { + // TODO + return 0; +} + +double sqrt(double x) { + // TODO + return 0; +} +double log(double x) { + // TODO + return 0; +} +double log2(double x) { + // TODO + return 0; +} +double log10(double x) { + // TODO + return 0; +} +double exp(double x) { + // TODO + return 0; +} +double frexp(double x, int *exp) { + // TODO + return 0; +} +double pow(double x, double y) { + // TODO + return 0; +} + +/* vim: set sts=0 ts=4 sw=4 tw=0 noet :*/ diff --git a/src/lib/libc/setjmp.s b/src/lib/libc/setjmp.s new file mode 100644 index 0000000..164cc5b --- /dev/null +++ b/src/lib/libc/setjmp.s @@ -0,0 +1,53 @@ +[GLOBAL setjmp] +setjmp: + ; Store general purpose registers + ; (in new stack frame) + mov [esp+4], eax + mov [esp+8], ebx + mov [esp+12], ecx + mov [esp+16], edx + mov [esp+20], edi + mov [esp+24], esi + mov [esp+28], ebp + mov [esp+32], esp + + ; Store flags + pushf + pop eax + mov [esp+36], eax + + ; Store return address + mov eax, [esp] + mov [esp+40], eax + + ; return 0 + xor eax, eax + ret + + +[GLOBAL longjmp] +longjmp: + ; on previous stack, resume return address + mov eax, [esp+32] + mov ebx, [esp+40] + mov [eax], ebx + + ; resume flags + mov eax, [esp+36] + push eax + popf + + ; load return value in eax + mov eax, [esp+44] + ; resume geneal purpose registers, except eax/esp + mov ebx, [esp+8] + mov ecx, [esp+12] + mov edx, [esp+16] + mov edi, [esp+20] + mov esi, [esp+24] + mov ebp, [esp+28] + + ; resume previous esp + mov esp, [esp+32] + ; return as if we were the setjmp call + ret diff --git a/src/lib/libc/signal.c b/src/lib/libc/signal.c new file mode 100644 index 0000000..e9037c1 --- /dev/null +++ b/src/lib/libc/signal.c @@ -0,0 +1,8 @@ +#include <signal.h> + +void (*signal(int sig, void (*func)(int)))(int) { + // TODO + return 0; +} + +/* vim: set sts=0 ts=4 sw=4 tw=0 noet :*/ diff --git a/src/lib/libc/stdio.c b/src/lib/libc/stdio.c index 22be78e..bd6c35b 100644 --- a/src/lib/libc/stdio.c +++ b/src/lib/libc/stdio.c @@ -60,4 +60,156 @@ int printf(const char* fmt, ...) { return puts(buffer); } +// ================== +// BELOW IS TODO +// ================== + + +int fgetc(FILE *stream) { + // TODO + return 0; +} +char *fgets(char *s, int size, FILE *stream) { + // TODO + return 0; +} +int getc(FILE *stream) { + // TODO + return 0; +} +int ungetc(int c, FILE *stream) { + // TODO + return 0; +} + +int fputc(int c, FILE *stream) { + // TODO + return 0; +} +int fputs(const char *s, FILE *stream) { + // TODO + return 0; +} +int putc(int c, FILE *stream) { + // TODO + return 0; +} + +FILE *fopen(const char *path, const char *mode) { + // TODO + return 0; +} +FILE *freopen(const char *path, const char *mode, FILE *stream) { + // TODO + return 0; +} + +void clearerr(FILE *stream) { + // TODO +} +int feof(FILE *stream) { + // TODO + return 0; +} +int ferror(FILE *stream) { + // TODO + return 0; +} +int fileno(FILE *stream) { + // TODO + return 0; +} + + +size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream) { + // TODO + return 0; +} +size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) { + // TODO + return 0; +} + +int fflush(FILE* f) { + // TODO + return 0; +} +int fclose(FILE* f) { + // TODO + return 0; +} + +FILE *stdin = 0; +FILE *stdout = 0; +FILE *stderr = 0; + +void setbuf(FILE *stream, char *buf) { + // TODO +} +void setbuffer(FILE *stream, char *buf, size_t size) { + // TODO +} +void setlinebuf(FILE *stream) { + // TODO +} +int setvbuf(FILE *stream, char *buf, int mode, size_t size) { + // TODO + return 0; +} + + +int fseek(FILE *stream, long offset, int whence) { + // TODO + return 0; +} +long ftell(FILE *stream) { + // TODO + return 0; +} +void rewind(FILE *stream) { + // TODO +} +int fgetpos(FILE *stream, fpos_t *pos) { + // TODO + return 0; +} +int fsetpos(FILE *stream, const fpos_t *pos) { + // TODO + return 0; +} + +FILE *tmpfile(void) { + // TODO + return 0; +} +char *tmpnam(char *s) { + // TODO + return 0; +} + +int rename(const char *old, const char *new) { + // TODO + return 0; +} +int remove(const char *pathname) { + // TODO + return 0; +} + + + +int fprintf(FILE *stream, const char *format, ...) { + // TODO + return 0; +} +int dprintf(int fd, const char *format, ...) { + // TODO + return 0; +} +int sprintf(char *str, const char *format, ...) { + // TODO + return 0; +} + + /* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/lib/libc/stdlib.c b/src/lib/libc/stdlib.c new file mode 100644 index 0000000..d8598dd --- /dev/null +++ b/src/lib/libc/stdlib.c @@ -0,0 +1,80 @@ +#include <stdlib.h> +#include <ctype.h> + +#include <kogata/debug.h> + +int rand(void) { + return 0; // TODO +} + +void srand(unsigned int seed) { + //TODO +} + +void abort() { + PANIC("Aborted."); +} + +float strtof(const char *nptr, const char **endptr) { + return (float)strtod(nptr, endptr); +} +double strtod(const char *nptr, const char **endptr) { + // TODO: better (inf, nan, ...) + + const char* p = nptr; + while (isspace(*p)) p++; + + double val = 0; + double sign = 1; + if (*p == '-') sign = -1; + if (*p == '-' || *p == '+') p++; + while (isdigit(*p)) { + val = val*10. + (double)((int)*p - '0'); + p++; + } + if (*p == '.') { + p++; + double fac = 0.1; + while (isdigit(*p)) { + val += fac * (double)((int)*p - '0'); + fac /= 10.; + p++; + } + } + if (*p == 'e' || *p == 'E') { + p++; + int exp = 0; + int sexp = 1; + if (*p == '-') sexp = -1; + if (*p == '-' || *p =='+') p++; + while (isdigit(*p)) { + exp = exp * 10 + (*p - '0'); + p++; + } + if (sexp == 1) { + for (int i = 0; i < exp; i++) val *= 10; + } else { + for (int i = 0; i < exp; i++) val /= 10; + } + } + if (endptr != NULL) *endptr = p-1; + + return val * sign; +} + +char *getenv(const char *name) { + // TODO + return 0; +} + +int system(const char *command) { + // TODO + return -1; +} + +int abs(int j) { + if (j < 0) return -j; + return j; +} + +/* vim: set sts=0 ts=4 sw=4 tw=0 noet :*/ diff --git a/src/lib/libc/time.c b/src/lib/libc/time.c new file mode 100644 index 0000000..c10d071 --- /dev/null +++ b/src/lib/libc/time.c @@ -0,0 +1,50 @@ +#include <time.h> + +time_t time(time_t* t) { + // TODO + return 0; +} +double difftime(time_t time1, time_t time0) { + // TODO + return 0; +} + +char *asctime(const struct tm *tm) { + // TODO -- + return 0; +} + +char *ctime(const time_t *timep) { + // TODO -- + return 0; +} + +struct tm *gmtime(const time_t *timep) { + // TODO + return 0; +} + +struct tm *localtime(const time_t *timep) { + // TODO + return 0; +} + +time_t mktime(struct tm *tm) { + // TODO + return 0; +} + +size_t strftime(char *s, size_t max, const char *format, const struct tm *tm) { + // TODO + return 0; +} + + +clock_t clock(void) { + // TODO + return 0; +} + + + +/* vim: set sts=0 ts=4 sw=4 tw=0 noet :*/ diff --git a/src/lib/lua/luaconf.h b/src/lib/lua/luaconf.h index fb6fe9c..c6592fb 100644 --- a/src/lib/lua/luaconf.h +++ b/src/lib/lua/luaconf.h @@ -39,7 +39,7 @@ ** ensure that all software connected to Lua will be compiled with the ** same configuration. */ -#define LUA_32BITS +// #define LUA_32BITS /* |