From 05498860e8f7b1e8bb27880bc7526de026694804 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Fri, 26 Mar 2021 21:55:50 +0100 Subject: Renamed libs Cleaner and more flexible. --- libs/libgui/msg.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 libs/libgui/msg.c (limited to 'libs/libgui/msg.c') diff --git a/libs/libgui/msg.c b/libs/libgui/msg.c new file mode 100644 index 0000000..73af242 --- /dev/null +++ b/libs/libgui/msg.c @@ -0,0 +1,31 @@ +// MIT License, Copyright (c) 2021 Marvin Borner + +#include +#include +#include +#include +#include + +res msg_send(u32 pid, enum message_type type, void *data, u32 size) +{ + if (!data) + return -EFAULT; + assert((signed)pid != -1 && size >= sizeof(struct message_header)); + char path[32] = { 0 }; + sprintf(path, "/proc/%d/msg", pid); + struct message_header *header = data; + header->magic = MSG_MAGIC; + header->src = getpid(); + header->type = type; + return write(path, data, 0, size); +} + +res msg_receive(void *buf, u32 size) +{ + int ret = read("/proc/self/msg", buf, 0, size); + struct message_header *header = buf; + if (header->magic == MSG_MAGIC) + return ret; + else + return -1; +} -- cgit v1.2.3