summaryrefslogtreecommitdiff
path: root/src/user/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/user/lib')
-rw-r--r--src/user/lib/esemaphore.c18
-rw-r--r--src/user/lib/stdlib.c13
-rw-r--r--src/user/lib/stdlib.h6
3 files changed, 25 insertions, 12 deletions
diff --git a/src/user/lib/esemaphore.c b/src/user/lib/esemaphore.c
index ed42ee9..2fdd659 100644
--- a/src/user/lib/esemaphore.c
+++ b/src/user/lib/esemaphore.c
@@ -21,7 +21,7 @@ struct evil_sem *esem_new(int value) {
if (!(sem = malloc(sizeof *sem))) goto fail_malloc;
if (!_syscall_fork(FORK_NOREAP, NULL)) {
- _syscall_close(ends_signal[1]);
+ close(ends_signal[1]);
while (_syscall_read(ends_signal[0], NULL, 0, 0) >= 0) {
if (!_syscall_fork(FORK_NOREAP, NULL)) {
_syscall_write(ends_wait[1], NULL, 0, 0);
@@ -30,8 +30,8 @@ struct evil_sem *esem_new(int value) {
}
_syscall_exit(0);
}
- _syscall_close(ends_signal[0]);
- _syscall_close(ends_wait[1]);
+ close(ends_signal[0]);
+ close(ends_wait[1]);
sem->wait = ends_wait[0];
sem->signal = ends_signal[1];
@@ -40,16 +40,16 @@ struct evil_sem *esem_new(int value) {
return sem;
fail_malloc:
- _syscall_close(ends_signal[0]);
- _syscall_close(ends_signal[1]);
+ close(ends_signal[0]);
+ close(ends_signal[1]);
fail_signal:
- _syscall_close(ends_wait[0]);
- _syscall_close(ends_wait[1]);
+ close(ends_wait[0]);
+ close(ends_wait[1]);
return NULL;
}
void esem_free(struct evil_sem *sem) {
- _syscall_close(sem->wait);
- _syscall_close(sem->signal);
+ close(sem->wait);
+ close(sem->signal);
free(sem);
}
diff --git a/src/user/lib/stdlib.c b/src/user/lib/stdlib.c
index c055d04..32b4f06 100644
--- a/src/user/lib/stdlib.c
+++ b/src/user/lib/stdlib.c
@@ -62,7 +62,7 @@ libc_file *file_open(const char *path, int flags) {
f = malloc(sizeof *f);
if (!f) {
- _syscall_close(h);
+ close(h);
return NULL;
}
f->pos = 0;
@@ -114,7 +114,16 @@ int file_write(libc_file *f, const char *buf, size_t len) {
}
void file_close(libc_file *f) {
- if (f->fd > 0) _syscall_close(f->fd);
+ if (f->fd > 0) close(f->fd);
if (f != &_stdin_null && f != &_stdout_null)
free(f);
}
+
+
+int fork(void) {
+ return _syscall_fork(0, NULL);
+}
+
+int close(handle_t h) {
+ return _syscall_close(h);
+}
diff --git a/src/user/lib/stdlib.h b/src/user/lib/stdlib.h
index 9bbcc5f..22227e3 100644
--- a/src/user/lib/stdlib.h
+++ b/src/user/lib/stdlib.h
@@ -1,8 +1,9 @@
#pragma once
-#include <user/lib/malloc.h>
#include <shared/mem.h>
+#include <shared/types.h>
#include <stdbool.h>
#include <stddef.h>
+#include <user/lib/malloc.h>
int printf(const char *fmt, ...);
int snprintf(char *str, size_t len, const char *fmt, ...);
@@ -21,3 +22,6 @@ int file_write(libc_file*, const char *buf, size_t len);
void file_close(libc_file*);
extern libc_file *stdin, *stdout;
+
+int fork(void);
+int close(handle_t h);