]> git.proxmox.com Git - wasi-libc.git/blob - libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c
Wasi snapshot preview1 (#140)
[wasi-libc.git] / libc-bottom-half / cloudlibc / src / libc / sys / socket / shutdown.c
1 // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/
2 //
3 // SPDX-License-Identifier: BSD-2-Clause
4
5 #include <common/errno.h>
6
7 #include <sys/socket.h>
8
9 #include <assert.h>
10 #include <wasi/api.h>
11 #include <errno.h>
12
13 #ifdef __wasilibc_unmodified_upstream // generated constant names
14 static_assert(SHUT_RD == __WASI_SHUT_RD, "Value mismatch");
15 static_assert(SHUT_WR == __WASI_SHUT_WR, "Value mismatch");
16 #else
17 static_assert(SHUT_RD == __WASI_SDFLAGS_RD, "Value mismatch");
18 static_assert(SHUT_WR == __WASI_SDFLAGS_WR, "Value mismatch");
19 #endif
20
21 int shutdown(int socket, int how) {
22 // Validate shutdown flags.
23 if (how != SHUT_RD && how != SHUT_WR && how != SHUT_RDWR) {
24 errno = EINVAL;
25 return -1;
26 }
27
28 __wasi_errno_t error = __wasi_sock_shutdown(socket, how);
29 if (error != 0) {
30 errno = errno_fixup_socket(socket, error);
31 return -1;
32 }
33 return error;
34 }