diff options
| author | Xavier Del Campo Romero <xavi92@disroot.org> | 2025-07-06 22:12:11 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi92@disroot.org> | 2025-09-08 21:10:27 +0200 |
| commit | 2adbeb903b431cf4bffcf29a6856eaba30581c22 (patch) | |
| tree | 337f4323364d711fc2513a2a41690932ae8d4465 /src | |
| parent | c849930b5319373978180569506180570320e978 (diff) | |
| download | wnix-2adbeb903b431cf4bffcf29a6856eaba30581c22.tar.gz | |
Setup aio skeleton
Diffstat (limited to 'src')
| -rw-r--r-- | src/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/aio/CMakeLists.txt | 6 | ||||
| -rw-r--r-- | src/aio/include/aio.h | 35 | ||||
| -rw-r--r-- | src/aio/private_include/aio/types.h | 16 | ||||
| -rw-r--r-- | src/aio/src/close.c | 34 | ||||
| -rw-r--r-- | src/aio/src/open.c | 33 | ||||
| -rw-r--r-- | src/main.c | 23 |
7 files changed, 147 insertions, 1 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7420122..0f28e58 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,6 +21,7 @@ target_link_libraries(${PROJECT_NAME} PRIVATE nanowasm) set(cflags ${cflags} -Wall -ffunction-sections -fdata-sections -pedantic) set(components + aio ) set(interfaces diff --git a/src/aio/CMakeLists.txt b/src/aio/CMakeLists.txt new file mode 100644 index 0000000..3f4561a --- /dev/null +++ b/src/aio/CMakeLists.txt @@ -0,0 +1,6 @@ +set(src + "src/close.c" + "src/open.c" +) +add_library(aio ${src}) +target_include_directories(aio PUBLIC "include" PRIVATE "private_include") diff --git a/src/aio/include/aio.h b/src/aio/include/aio.h new file mode 100644 index 0000000..f9f76cb --- /dev/null +++ b/src/aio/include/aio.h @@ -0,0 +1,35 @@ +/* + * wanix, a Unix-like operating system for WebAssembly + * 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 AIO_H +#define AIO_H + +#include <stddef.h> + +enum +{ + AIO_POLLIN = 1, + AIO_POLLOUT = 1 << 1 +}; + +struct aio *aio_open(const char *path, const char *mode); +int aio_poll(struct aio **io, size_t n); +int aio_event(const struct aio *io, int ev); +int aio_close(struct aio *io); + +#endif diff --git a/src/aio/private_include/aio/types.h b/src/aio/private_include/aio/types.h new file mode 100644 index 0000000..31ee414 --- /dev/null +++ b/src/aio/private_include/aio/types.h @@ -0,0 +1,16 @@ +#ifndef AIO_PRV_OPEN_H +#define AIO_PRV_OPEN_H + +enum aio_state +{ + AIO_OK, + AIO_AGAIN, + AIO_FATAL +}; + +struct aio +{ + enum aio_state (*next)(struct aio *); +}; + +#endif diff --git a/src/aio/src/close.c b/src/aio/src/close.c new file mode 100644 index 0000000..a6067a8 --- /dev/null +++ b/src/aio/src/close.c @@ -0,0 +1,34 @@ +/* + * wanix, a Unix-like operating system for WebAssembly + * 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 <aio.h> +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> + +int aio_close(struct aio *const aio) +{ + if (!aio) + { + errno = EINVAL; + return EOF; + } + + free(aio); + return 0; +} diff --git a/src/aio/src/open.c b/src/aio/src/open.c new file mode 100644 index 0000000..89fbbba --- /dev/null +++ b/src/aio/src/open.c @@ -0,0 +1,33 @@ +/* + * wanix, a Unix-like operating system for WebAssembly + * 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 <aio/types.h> +#include <stddef.h> +#include <stdlib.h> + +struct aio *aio_open(const char *const path, const char *const mode) +{ + struct aio *const ret = malloc(sizeof *ret); + + if (!ret) + goto failure; + +failure: + free(ret); + return NULL; +} @@ -16,10 +16,31 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ +#include <aio.h> +#include <errno.h> +#include <stdio.h> #include <stdlib.h> +#include <string.h> int main(void) { - int ret = EXIT_SUCCESS; + int ret = EXIT_FAILURE; + struct aio *aio = aio_open("/media/cdrom/", "rb"); + + if (!aio) + { + fprintf(stderr, "%s: aio_open failed: %s\n", __func__, strerror(errno)); + goto end; + } + + ret = EXIT_SUCCESS; + +end: + if (aio && aio_close(aio)) + { + fprintf(stderr, "%s: aio_close failed: %s\n", __func__, strerror(errno)); + ret = EXIT_FAILURE; + } + return ret; } |
