summaryrefslogtreecommitdiff
path: root/src/user/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/user/lib')
-rw-r--r--src/user/lib/stdlib.c17
-rw-r--r--src/user/lib/stdlib.h1
2 files changed, 18 insertions, 0 deletions
diff --git a/src/user/lib/stdlib.c b/src/user/lib/stdlib.c
index 32b4f06..56b8bb4 100644
--- a/src/user/lib/stdlib.c
+++ b/src/user/lib/stdlib.c
@@ -94,6 +94,23 @@ fail:
return NULL;
}
+libc_file *file_clone(const libc_file *f) {
+ handle_t h = _syscall_dup(f->fd, -1, 0);
+ libc_file *f2;
+ if (h < 0) return NULL;
+
+ // TODO file_wrapfd
+ f2 = malloc(sizeof *f2);
+ if (!f2) {
+ close(h);
+ return NULL;
+ }
+ f2->pos = f->pos;
+ f2->eof = f->eof;
+ f2->fd = h;
+ return f2;
+}
+
int file_read(libc_file *f, char *buf, size_t len) {
if (f->fd < 0) return -1;
diff --git a/src/user/lib/stdlib.h b/src/user/lib/stdlib.h
index 22227e3..1982e85 100644
--- a/src/user/lib/stdlib.h
+++ b/src/user/lib/stdlib.h
@@ -17,6 +17,7 @@ typedef struct {
} libc_file;
libc_file *file_open(const char *path, int flags);
libc_file *file_reopen(libc_file*, const char *path, int flags);
+libc_file *file_clone(const libc_file*);
int file_read(libc_file*, char *buf, size_t len);
int file_write(libc_file*, const char *buf, size_t len);
void file_close(libc_file*);