diff options
Diffstat (limited to 'src/user/lib')
-rw-r--r-- | src/user/lib/include/stdio.h | 8 | ||||
-rw-r--r-- | src/user/lib/include/string.h | 2 | ||||
-rw-r--r-- | src/user/lib/std/stdio.c | 25 | ||||
-rw-r--r-- | src/user/lib/std/string.c | 2 |
4 files changed, 29 insertions, 8 deletions
diff --git a/src/user/lib/include/stdio.h b/src/user/lib/include/stdio.h index 91fe169..6c3a974 100644 --- a/src/user/lib/include/stdio.h +++ b/src/user/lib/include/stdio.h @@ -3,11 +3,19 @@ #include <stdarg.h> +extern FILE term; + +void print(char *s); +void printf(char *s, ...); +char *readln(); + void fprint(FILE f, char *s); void fprint_int(FILE f, int number); void fprint_hex(FILE f, unsigned number); void fprintf(FILE f, char *s, ...); +void vsfprintf(FILE f, char *s, va_list arg); + char* freadln(FILE f); #endif diff --git a/src/user/lib/include/string.h b/src/user/lib/include/string.h index f14af35..87d8da2 100644 --- a/src/user/lib/include/string.h +++ b/src/user/lib/include/string.h @@ -14,7 +14,7 @@ uint16_t *memsetw(uint16_t *dest, uint16_t val, int count); int strlen(const char *str); char *strcpy(char *dest, const char *src); char *strdup(const char *src); -char *strchr(const char *str, char c); +char *strchr(const char *str, int c); char *strcat(char *dest, const char *src); int strcmp(const char *s1, const char *s2); diff --git a/src/user/lib/std/stdio.c b/src/user/lib/std/stdio.c index 2bce2e3..1628a78 100644 --- a/src/user/lib/std/stdio.c +++ b/src/user/lib/std/stdio.c @@ -2,6 +2,24 @@ #include <stdio.h> #include <tce/syscall.h> +FILE term = 0; +void print(char *s) { fprint(term, s); } +void printf(char *format, ...) { + va_list ap; + va_start(ap, format); + vsfprintf(term, format, ap); + va_end(ap); +} +char* readln() { return freadln(term); } + +void fprintf(FILE f, char* format, ...) { + va_list ap; + va_start(ap, format); + vsfprintf(f, format, ap); + va_end(ap); +} + + void fprint(FILE f, char *s) { write(f, 0, strlen(s), s); } @@ -54,10 +72,7 @@ void fprint_hex(FILE f, unsigned v) { fprint(f, s); } -void fprintf(FILE f, char* format, ...) { - va_list ap; - va_start(ap, format); - +void vsfprintf(FILE f, char *format, va_list ap) { char* start = format; while (*format) { @@ -78,8 +93,6 @@ void fprintf(FILE f, char* format, ...) { } } if (start != format) write(f, 0, format - start, start); - - va_end(ap); } char* freadln(FILE f) { diff --git a/src/user/lib/std/string.c b/src/user/lib/std/string.c index 7cd8ede..21dbd03 100644 --- a/src/user/lib/std/string.c +++ b/src/user/lib/std/string.c @@ -6,7 +6,7 @@ int strlen(const char *str) { return i-1; } -char *strchr(const char *str, char c) { +char *strchr(const char *str, int c) { while (*str) { if (*str == c) return (char*)str; str++; |