--- /dev/null
+/*
+ * This file is part of the Corax operating system.
+ * Copyright (C) 2020 Matthias Kruk
+ *
+ * Corax is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Corax is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Corax. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <crxstd.h>
+#include <corax/ipc/io.h>
+#include "proc.h"
+#include "filedesc.h"
+
+ssize_t sys_write(const pid_t pid, struct cxio_write *msg)
+{
+ struct proc *proc;
+ struct filedesc *filedesc;
+ struct cxmsg resp;
+ struct cxio_response *ioresp;
+ ssize_t ret_val;
+
+ ret_val = proc_lookup(pid, &proc);
+
+ ioresp = (struct cxio_response*)resp.cm_data;
+
+ memset(&resp, 0, sizeof(resp));
+
+ if(!ret_val) {
+ ret_val = proc_get_fd(proc, msg->fd, &filedesc);
+
+ if(!ret_val) {
+ ret_val = fd_write(filedesc, msg->data, msg->datalen);
+
+ if(ret_val >= 0) {
+ ioresp->retval = ret_val;
+ ioresp->error = 0;
+ }
+ }
+ }
+
+ if(ret_val < 0) {
+ ioresp->retval = -1;
+ ioresp->error = -ret_val;
+ }
+
+ ioresp->fd = msg->fd;
+ resp.cm_type = CXIO_RESPONSE;
+ resp.cm_len = sizeof(*ioresp);
+
+ ret_val = cxsend(pid, &resp);
+
+ return(ret_val);
+}