lib: c: re-organise into separate static modules, plus a single shared library
This commit is contained in:
0
lib/libc/io/unistd/close.c
Normal file
0
lib/libc/io/unistd/close.c
Normal file
6
lib/libc/io/unistd/mmap.c
Normal file
6
lib/libc/io/unistd/mmap.c
Normal file
@@ -0,0 +1,6 @@
|
||||
#include <sys/mman.h>
|
||||
|
||||
void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
40
lib/libc/io/unistd/open.c
Normal file
40
lib/libc/io/unistd/open.c
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <errno.h>
|
||||
#include <mango/handle.h>
|
||||
#include <mango/msg.h>
|
||||
#include <rosetta/fs.h>
|
||||
#include <sys/remote.h>
|
||||
|
||||
int open(const char *path, int flags)
|
||||
{
|
||||
tid_t remote_tid;
|
||||
unsigned int remote_chid;
|
||||
if (!sys_remote_get(SYS_REMOTE_NSD, &remote_tid, &remote_chid)) {
|
||||
return __set_errno(ENXIO);
|
||||
}
|
||||
|
||||
kern_handle_t port;
|
||||
kern_status_t status = port_create(&port);
|
||||
if (status != KERN_OK) {
|
||||
return __set_errno(__errno_from_kern_status(status));
|
||||
}
|
||||
|
||||
status = port_connect(port, remote_tid, remote_chid);
|
||||
if (status != KERN_OK) {
|
||||
kern_handle_close(port);
|
||||
return __set_errno(__errno_from_kern_status(status));
|
||||
}
|
||||
|
||||
int err = SUCCESS;
|
||||
status = fs_open(port, path, flags, &err);
|
||||
if (status != KERN_OK) {
|
||||
kern_handle_close(port);
|
||||
return __set_errno(__errno_from_kern_status(status));
|
||||
}
|
||||
|
||||
if (err != SUCCESS) {
|
||||
kern_handle_close(port);
|
||||
return __set_errno(err);
|
||||
}
|
||||
|
||||
return (int)port;
|
||||
}
|
||||
21
lib/libc/io/unistd/read.c
Normal file
21
lib/libc/io/unistd/read.c
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <errno.h>
|
||||
#include <mango/handle.h>
|
||||
#include <mango/msg.h>
|
||||
#include <rosetta/fs.h>
|
||||
#include <sys/remote.h>
|
||||
|
||||
int read(int fd, void *buf, size_t count)
|
||||
{
|
||||
int err;
|
||||
size_t nr_read;
|
||||
kern_status_t status = fs_read(fd, count, &err, &nr_read, buf, count);
|
||||
if (status != KERN_OK) {
|
||||
return __set_errno(__errno_from_kern_status(status));
|
||||
}
|
||||
|
||||
if (err != SUCCESS) {
|
||||
return __set_errno(err);
|
||||
}
|
||||
|
||||
return nr_read;
|
||||
}
|
||||
0
lib/libc/io/unistd/write.c
Normal file
0
lib/libc/io/unistd/write.c
Normal file
Reference in New Issue
Block a user