summaryrefslogtreecommitdiff
path: root/src/user/lib/libc/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/user/lib/libc/include')
-rw-r--r--src/user/lib/libc/include/ctype.h24
-rw-r--r--src/user/lib/libc/include/readline.h4
-rw-r--r--src/user/lib/libc/include/setjmp.h25
-rw-r--r--src/user/lib/libc/include/stdio.h53
-rw-r--r--src/user/lib/libc/include/stdlib.h15
-rw-r--r--src/user/lib/libc/include/string.h5
-rw-r--r--src/user/lib/libc/include/tce/syscall.h16
7 files changed, 125 insertions, 17 deletions
diff --git a/src/user/lib/libc/include/ctype.h b/src/user/lib/libc/include/ctype.h
new file mode 100644
index 0000000..10a64df
--- /dev/null
+++ b/src/user/lib/libc/include/ctype.h
@@ -0,0 +1,24 @@
+#ifndef DEF_LIBC_CTYPE_H
+#define DEF_LIBC_CTYPE_H
+
+#include <types.h>
+
+#ifdef __cplusplus
+extern "C" { namespace libc {
+#endif
+
+
+int isalpha(int c);
+int isdigit(int c);
+int isalnum(int c);
+
+int tolower(int c);
+int toupper(int c);
+
+
+#ifdef __cplusplus
+} }
+#endif
+
+#endif
+
diff --git a/src/user/lib/libc/include/readline.h b/src/user/lib/libc/include/readline.h
index 1ec5baa..9fa2ee7 100644
--- a/src/user/lib/libc/include/readline.h
+++ b/src/user/lib/libc/include/readline.h
@@ -14,8 +14,8 @@ typedef struct _rdln_hist {
extern "C" { namespace libc {
#endif
char *readln();
-char* freadln(FILE f); // minimal line-reading function. user must free the returned value.
-char* freadline(FILE f, readline_history *h);
+char* freadln(FILE *f); // minimal line-reading function. user must free the returned value.
+char* freadline(FILE *f, readline_history *h);
#ifdef __cplusplus
} }
#endif
diff --git a/src/user/lib/libc/include/setjmp.h b/src/user/lib/libc/include/setjmp.h
new file mode 100644
index 0000000..3bf2027
--- /dev/null
+++ b/src/user/lib/libc/include/setjmp.h
@@ -0,0 +1,25 @@
+#ifndef DEF_LIBC_SETJMP_H
+#define DEF_LIBC_SETJMP_H
+
+#include <types.h>
+
+typedef struct {
+ uint32_t ebp; //0
+ uint32_t ebx; //4
+ uint32_t edi; //8
+ uint32_t esi; //12
+ uint32_t esp; //16
+ uint32_t eip; //20
+} jmp_buf[1];
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+int setjmp(jmp_buf env);
+void longjmp(jmp_buf, int val);
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/src/user/lib/libc/include/stdio.h b/src/user/lib/libc/include/stdio.h
index 72d355a..8fbefcd 100644
--- a/src/user/lib/libc/include/stdio.h
+++ b/src/user/lib/libc/include/stdio.h
@@ -8,14 +8,57 @@
extern "C" { namespace libc {
#endif
+#define EOF 0x1E0F
+
+#define TERM_INPUT_BUFFER_SIZE 256
+
+typedef struct {
+ int fd;
+ long pos; // -1 : it's a stream
+ file_info info;
+ // terminal input buffer
+ // Possible states :
+ // - tib_u_begin = tib_u_end = tib_begin : buffer is empty
+ // - tib_begin = tib_u_begin < tib_u_end : buffer contains some data
+ // - tib_begin < tib_u_begin < tib_u_end : buffer contains some data that is
+ // being read, and some space for putting back characters
+ char *tib_begin, *tib_end, *tib_u_begin, *tib_u_end;
+ int term_echo; // enable echoing of entered keypresses ?
+
+} FILE;
+
extern FILE term;
+#define stdin (&term)
+#define stdout (&term)
+
+
+#define SEEK_SET 0x5EEC0001
+#define SEEK_CUR 0x5EEC0002
+#define SEEK_END 0x5EEC0003
+FILE *fopen(const char *path, const char *mode);
+void __tce_libc_fsetup(FILE *f); // INTERNAL
+
+// These two handle buffering for terminals
+int fgetc(FILE*);
+int ungetc(int, FILE*);
+
+// These do not handle buffering for terminals
+size_t fread(void* ptr, size_t size, size_t nmemb, FILE*);
+size_t fwrite(void* ptr, size_t size, size_t nmemb, FILE*);
+size_t fseek(FILE *stream, long offset, int whence);
+long ftell(FILE *stream);
+void fclose(FILE *f);
+
+int getchar();
+int scanf(const char *s, ...);
+
+int print(const char *s);
+int printf(const char *s, ...);
-void print(const char *s);
-void printf(const char *s, ...);
-void fprint(FILE f, const char *s);
-void fprintf(FILE f, const char *s, ...);
-void vfprintf(FILE f, const char *s, va_list arg);
+int fprint(FILE *f, const char *s);
+int fprintf(FILE *f, const char *s, ...);
+int vfprintf(FILE *f, const char *s, va_list arg);
#ifdef __cplusplus
} }
diff --git a/src/user/lib/libc/include/stdlib.h b/src/user/lib/libc/include/stdlib.h
index 1cc5d16..e1b3326 100644
--- a/src/user/lib/libc/include/stdlib.h
+++ b/src/user/lib/libc/include/stdlib.h
@@ -1,5 +1,5 @@
-#ifndef DEF_STDLIB_H
-#define DEF_STDLIB_H
+#ifndef DEF_LIBC_STDLIB_H
+#define DEF_LIBC_STDLIB_H
#include <types.h>
#include <tce/syscall.h>
@@ -8,8 +8,19 @@
extern "C" { namespace libc {
#endif
+int atoi(char*);
+double atof(char*);
+
+#define RAND_MAX 32767
+int rand();
+void srand(unsigned int);
+
+void exit(int);
void abort();
extern volatile int errno;
+
+
+
#ifdef __cplusplus
} }
#endif
diff --git a/src/user/lib/libc/include/string.h b/src/user/lib/libc/include/string.h
index 5b86868..2f4f4ca 100644
--- a/src/user/lib/libc/include/string.h
+++ b/src/user/lib/libc/include/string.h
@@ -18,6 +18,7 @@ char *strdup(const char *src);
char *strchr(const char *str, int c);
char *strcat(char *dest, const char *src);
int strcmp(const char *s1, const char *s2);
+char *strncpy(char *dest, const char *src, int max);
char* format_int(char* buf, int number);
char* format_hex(char *buf, unsigned v);
@@ -25,6 +26,10 @@ int printf_str_len(const char *fmt, va_list arg);
int vsprintf(char *buf, const char *fmt, va_list arg);
int sprintf(char *buf, const char *fmt, ...);
+
+void simplify_path(char *p); // simplifies /../, // and /./
+char *path_cat(const char *a, const char *b, int trailing_slash); // allocates a new buffer
+
#ifdef __cplusplus
} }
#endif
diff --git a/src/user/lib/libc/include/tce/syscall.h b/src/user/lib/libc/include/tce/syscall.h
index 6679f1a..4a1c6ef 100644
--- a/src/user/lib/libc/include/tce/syscall.h
+++ b/src/user/lib/libc/include/tce/syscall.h
@@ -23,17 +23,17 @@ int proc_priv();
void* sbrk(ptrdiff_t size);
void brk(void* ptr);
-int run(const char* file, const char** args, FILE zero_fd);
+int run(const char* file, const char** args, int zero_fd);
int waitpid(int pid, int block);
-FILE open(const char* filename, int mode);
-FILE open_relative(FILE root, const char* filename, int mode);
+int open(const char* filename, int mode);
+int open_relative(int root, const char* filename, int mode);
int stat(const char* filename, file_info *info);
-int stat_relative(FILE root, const char* filename, file_info *info);
-int statf(FILE file, file_info *info);
-void close(FILE file);
-int read(FILE file, size_t offset, size_t len, char *buffer);
-int write(FILE file, size_t offset, size_t len, const char *buffer);
+int stat_relative(int root, const char* filename, file_info *info);
+int statf(int file, file_info *info);
+void close(int file);
+int read(int file, size_t offset, size_t len, char *buffer);
+int write(int file, size_t offset, size_t len, const char *buffer);
int link(const char* from, const char* to, int mode);
#ifdef __cplusplus