summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/user/app/init/shell.c4
-rw-r--r--src/user/lib/elfload.c1
-rw-r--r--src/user/lib/file.h9
-rw-r--r--src/user/lib/include/bits/file.h10
-rw-r--r--src/user/lib/include/stdio.h6
-rw-r--r--src/user/lib/stdlib.c9
6 files changed, 28 insertions, 11 deletions
diff --git a/src/user/app/init/shell.c b/src/user/app/init/shell.c
index 253acce..e53d7d9 100644
--- a/src/user/app/init/shell.c
+++ b/src/user/app/init/shell.c
@@ -72,7 +72,7 @@ static void cmd_cat_ls(const char *args, bool ls) {
return;
}
- while (!file->eof) {
+ while (!feof(file)) {
int len = fread(buf, 1, sizeof buf, file);
if (len <= 0) break;
@@ -135,6 +135,8 @@ void shell_loop(void) {
printf("%x$ ", level);
readline(buf, 256);
+ if (feof(stdin))
+ _syscall_exit(0);
redir = strtrim(strsplit(buf, '>'));
cmd = strtrim(buf);
args = strtrim(strsplit(cmd, 0));
diff --git a/src/user/lib/elfload.c b/src/user/lib/elfload.c
index b73dfe5..a471513 100644
--- a/src/user/lib/elfload.c
+++ b/src/user/lib/elfload.c
@@ -1,6 +1,7 @@
#include <camellia/execbuf.h>
#include <camellia/flags.h>
#include <camellia/syscalls.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
diff --git a/src/user/lib/file.h b/src/user/lib/file.h
new file mode 100644
index 0000000..9630b6d
--- /dev/null
+++ b/src/user/lib/file.h
@@ -0,0 +1,9 @@
+#pragma once
+#include <stdbool.h>
+
+struct _LIBC_FILE {
+ int fd;
+ int pos;
+ bool eof;
+ bool error;
+};
diff --git a/src/user/lib/include/bits/file.h b/src/user/lib/include/bits/file.h
index e50d402..63a31c4 100644
--- a/src/user/lib/include/bits/file.h
+++ b/src/user/lib/include/bits/file.h
@@ -1,10 +1,2 @@
#pragma once
-#include <stdbool.h>
-// TODO make opaque
-struct FILE {
- int fd;
- int pos;
- bool eof;
- bool error;
-};
-typedef struct FILE FILE;
+typedef struct _LIBC_FILE FILE;
diff --git a/src/user/lib/include/stdio.h b/src/user/lib/include/stdio.h
index 2f0746f..b8de85d 100644
--- a/src/user/lib/include/stdio.h
+++ b/src/user/lib/include/stdio.h
@@ -16,6 +16,10 @@ FILE *fopen(const char *path, const char *mode);
FILE *freopen(const char *path, const char *mode, FILE *);
FILE *fdopen(int fd, const char *mode);
FILE *file_clone(const FILE *);
+int fclose(FILE *);
+
size_t fread(void *restrict ptr, size_t size, size_t nitems, FILE *restrict);
size_t fwrite(const void *restrict ptr, size_t size, size_t nitems, FILE *restrict);
-int fclose(FILE *);
+
+int feof(FILE *);
+int ferror(FILE *);
diff --git a/src/user/lib/stdlib.c b/src/user/lib/stdlib.c
index cd2ec90..0f49ccb 100644
--- a/src/user/lib/stdlib.c
+++ b/src/user/lib/stdlib.c
@@ -1,3 +1,4 @@
+#include "file.h"
#include <camellia/syscalls.h>
#include <errno.h>
#include <shared/printf.h>
@@ -200,6 +201,14 @@ int fclose(FILE *f) {
return 0;
}
+int feof(FILE *f) {
+ return f->eof;
+}
+
+int ferror(FILE *f) {
+ return f->error;
+}
+
int fork(void) {
return _syscall_fork(0, NULL);