aboutsummaryrefslogtreecommitdiff
path: root/src/drv/stdout
diff options
context:
space:
mode:
Diffstat (limited to 'src/drv/stdout')
-rw-r--r--src/drv/stdout/CMakeLists.txt20
-rw-r--r--src/drv/stdout/include/drv/stdout.h28
-rw-r--r--src/drv/stdout/private_include/drv/stdout/ops.h29
-rw-r--r--src/drv/stdout/private_include/drv/stdout/types.h32
-rw-r--r--src/drv/stdout/src/CMakeLists.txt22
-rw-r--r--src/drv/stdout/src/free.c32
-rw-r--r--src/drv/stdout/src/init.c35
-rw-r--r--src/drv/stdout/src/update.c47
-rw-r--r--src/drv/stdout/src/write.c29
9 files changed, 274 insertions, 0 deletions
diff --git a/src/drv/stdout/CMakeLists.txt b/src/drv/stdout/CMakeLists.txt
new file mode 100644
index 0000000..58f430a
--- /dev/null
+++ b/src/drv/stdout/CMakeLists.txt
@@ -0,0 +1,20 @@
+# wnix, a Unix-like operating system for WebAssembly applications.
+# Copyright (C) 2025 Xavier Del Campo Romero
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+add_library(drv_stdout)
+add_subdirectory(src)
+target_include_directories(drv_stdout PUBLIC include PRIVATE private_include)
+target_link_libraries(drv_stdout PUBLIC c PRIVATE drv_event)
diff --git a/src/drv/stdout/include/drv/stdout.h b/src/drv/stdout/include/drv/stdout.h
new file mode 100644
index 0000000..0fac80c
--- /dev/null
+++ b/src/drv/stdout/include/drv/stdout.h
@@ -0,0 +1,28 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef DRV_STDOUT_H
+#define DRV_STDOUT_H
+
+#include <drv/event.h>
+
+struct drv_port *drv_stdout_init(const struct drv_event *ev);
+int drv_stdout_update(struct drv_port *p);
+void drv_stdout_free(struct drv_port *p);
+
+#endif
diff --git a/src/drv/stdout/private_include/drv/stdout/ops.h b/src/drv/stdout/private_include/drv/stdout/ops.h
new file mode 100644
index 0000000..af848e3
--- /dev/null
+++ b/src/drv/stdout/private_include/drv/stdout/ops.h
@@ -0,0 +1,29 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef DRV_STDOUT_OPS_H
+#define DRV_STDOUT_OPS_H
+
+#include <drv/event.h>
+#include <drv/stdout/types.h>
+#include <stddef.h>
+
+int drv_stdout_write(struct drv_port *p, const void *buf, size_t n,
+ const struct drv_event_done *done);
+
+#endif
diff --git a/src/drv/stdout/private_include/drv/stdout/types.h b/src/drv/stdout/private_include/drv/stdout/types.h
new file mode 100644
index 0000000..a39ce64
--- /dev/null
+++ b/src/drv/stdout/private_include/drv/stdout/types.h
@@ -0,0 +1,32 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef DRV_STDOUT_TYPES_H
+#define DRV_STDOUT_TYPES_H
+
+#include <drv/event.h>
+#include <stdbool.h>
+#include <stddef.h>
+
+struct drv_port
+{
+ bool init;
+ struct drv_event ev;
+};
+
+#endif
diff --git a/src/drv/stdout/src/CMakeLists.txt b/src/drv/stdout/src/CMakeLists.txt
new file mode 100644
index 0000000..490886d
--- /dev/null
+++ b/src/drv/stdout/src/CMakeLists.txt
@@ -0,0 +1,22 @@
+# wnix, a Unix-like operating system for WebAssembly applications.
+# Copyright (C) 2025 Xavier Del Campo Romero
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+target_sources(drv_stdout PRIVATE
+ free.c
+ init.c
+ update.c
+ write.c
+)
diff --git a/src/drv/stdout/src/free.c b/src/drv/stdout/src/free.c
new file mode 100644
index 0000000..4b7d733
--- /dev/null
+++ b/src/drv/stdout/src/free.c
@@ -0,0 +1,32 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <drv/event.h>
+#include <drv/stdout.h>
+#include <drv/stdout/ops.h>
+#include <drv/stdout/types.h>
+#include <stddef.h>
+#include <stdlib.h>
+
+void drv_stdout_free(struct drv_port *const p)
+{
+ if (!p)
+ return;
+
+ free(p);
+}
diff --git a/src/drv/stdout/src/init.c b/src/drv/stdout/src/init.c
new file mode 100644
index 0000000..86f566a
--- /dev/null
+++ b/src/drv/stdout/src/init.c
@@ -0,0 +1,35 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <drv/event.h>
+#include <drv/stdout.h>
+#include <drv/stdout/ops.h>
+#include <drv/stdout/types.h>
+#include <stddef.h>
+#include <stdlib.h>
+
+struct drv_port *drv_stdout_init(const struct drv_event *const ev)
+{
+ struct drv_port *ret = NULL;
+
+ if (!(ret = malloc(sizeof *ret)))
+ return NULL;
+
+ *ret = (const struct drv_port){.ev = *ev};
+ return ret;
+}
diff --git a/src/drv/stdout/src/update.c b/src/drv/stdout/src/update.c
new file mode 100644
index 0000000..8b47a52
--- /dev/null
+++ b/src/drv/stdout/src/update.c
@@ -0,0 +1,47 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <drv/event.h>
+#include <drv/stdout.h>
+#include <drv/stdout/ops.h>
+#include <drv/stdout/types.h>
+#include <stdbool.h>
+
+static int init(struct drv_port *const p)
+{
+ if (p->init)
+ return 0;
+
+ const struct drv_event *const ev = &p->ev;
+ const struct drv_event_ops ops =
+ {
+ .write = drv_stdout_write,
+ .p = p
+ };
+
+ if (ev->status("stdout", &ops, true, 0666, ev->args))
+ return -1;
+
+ p->init = true;
+ return 0;
+}
+
+int drv_stdout_update(struct drv_port *const p)
+{
+ return init(p);
+}
diff --git a/src/drv/stdout/src/write.c b/src/drv/stdout/src/write.c
new file mode 100644
index 0000000..06d5980
--- /dev/null
+++ b/src/drv/stdout/src/write.c
@@ -0,0 +1,29 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <drv/event.h>
+#include <drv/stdout.h>
+#include <drv/stdout/types.h>
+#include <drv/stdout/ops.h>
+#include <stddef.h>
+
+int drv_stdout_write(struct drv_port *const p, const void *const buf,
+ const size_t n, const struct drv_event_done *const d)
+{
+ return n;
+}