lib: c: re-organise into separate static modules, plus a single shared library
This commit is contained in:
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;
|
||||
}
|
||||
Reference in New Issue
Block a user