diff options
Diffstat (limited to 'src/drv/stderr')
| -rw-r--r-- | src/drv/stderr/CMakeLists.txt | 20 | ||||
| -rw-r--r-- | src/drv/stderr/include/drv/stderr.h | 28 | ||||
| -rw-r--r-- | src/drv/stderr/private_include/drv/stderr/ops.h | 29 | ||||
| -rw-r--r-- | src/drv/stderr/private_include/drv/stderr/types.h | 32 | ||||
| -rw-r--r-- | src/drv/stderr/src/CMakeLists.txt | 22 | ||||
| -rw-r--r-- | src/drv/stderr/src/free.c | 32 | ||||
| -rw-r--r-- | src/drv/stderr/src/init.c | 35 | ||||
| -rw-r--r-- | src/drv/stderr/src/update.c | 47 | ||||
| -rw-r--r-- | src/drv/stderr/src/write.c | 29 |
9 files changed, 274 insertions, 0 deletions
diff --git a/src/drv/stderr/CMakeLists.txt b/src/drv/stderr/CMakeLists.txt new file mode 100644 index 0000000..cb9a07a --- /dev/null +++ b/src/drv/stderr/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_stderr) +add_subdirectory(src) +target_include_directories(drv_stderr PUBLIC include PRIVATE private_include) +target_link_libraries(drv_stderr PUBLIC c PRIVATE drv_event) diff --git a/src/drv/stderr/include/drv/stderr.h b/src/drv/stderr/include/drv/stderr.h new file mode 100644 index 0000000..eceff6a --- /dev/null +++ b/src/drv/stderr/include/drv/stderr.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_STDERR_H +#define DRV_STDERR_H + +#include <drv/event.h> + +struct drv_port *drv_stderr_init(const struct drv_event *ev); +int drv_stderr_update(struct drv_port *p); +void drv_stderr_free(struct drv_port *p); + +#endif diff --git a/src/drv/stderr/private_include/drv/stderr/ops.h b/src/drv/stderr/private_include/drv/stderr/ops.h new file mode 100644 index 0000000..a265b15 --- /dev/null +++ b/src/drv/stderr/private_include/drv/stderr/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_STDERR_OPS_H +#define DRV_STDERR_OPS_H + +#include <drv/event.h> +#include <drv/stderr/types.h> +#include <stddef.h> + +int drv_stderr_write(struct drv_port *p, const void *buf, size_t n, + const struct drv_event_done *done); + +#endif diff --git a/src/drv/stderr/private_include/drv/stderr/types.h b/src/drv/stderr/private_include/drv/stderr/types.h new file mode 100644 index 0000000..196568c --- /dev/null +++ b/src/drv/stderr/private_include/drv/stderr/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_STDERR_TYPES_H +#define DRV_STDERR_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/stderr/src/CMakeLists.txt b/src/drv/stderr/src/CMakeLists.txt new file mode 100644 index 0000000..fd685c8 --- /dev/null +++ b/src/drv/stderr/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_stderr PRIVATE + free.c + init.c + update.c + write.c +) diff --git a/src/drv/stderr/src/free.c b/src/drv/stderr/src/free.c new file mode 100644 index 0000000..1793540 --- /dev/null +++ b/src/drv/stderr/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/stderr.h> +#include <drv/stderr/ops.h> +#include <drv/stderr/types.h> +#include <stddef.h> +#include <stdlib.h> + +void drv_stderr_free(struct drv_port *const p) +{ + if (!p) + return; + + free(p); +} diff --git a/src/drv/stderr/src/init.c b/src/drv/stderr/src/init.c new file mode 100644 index 0000000..95797d7 --- /dev/null +++ b/src/drv/stderr/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/stderr.h> +#include <drv/stderr/ops.h> +#include <drv/stderr/types.h> +#include <stddef.h> +#include <stdlib.h> + +struct drv_port *drv_stderr_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/stderr/src/update.c b/src/drv/stderr/src/update.c new file mode 100644 index 0000000..24e0cf4 --- /dev/null +++ b/src/drv/stderr/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/stderr.h> +#include <drv/stderr/ops.h> +#include <drv/stderr/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_stderr_write, + .p = p + }; + + if (ev->status("stderr", &ops, true, 0666, ev->args)) + return -1; + + p->init = true; + return 0; +} + +int drv_stderr_update(struct drv_port *const p) +{ + return init(p); +} diff --git a/src/drv/stderr/src/write.c b/src/drv/stderr/src/write.c new file mode 100644 index 0000000..2f5ccf8 --- /dev/null +++ b/src/drv/stderr/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/stderr.h> +#include <drv/stderr/types.h> +#include <drv/stderr/ops.h> +#include <stddef.h> + +int drv_stderr_write(struct drv_port *const p, const void *const buf, + const size_t n, const struct drv_event_done *const d) +{ + return n; +} |
