]>
Commit | Line | Data |
---|---|---|
320054e8 DG |
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> | |
446cb3f1 | 10 | #include <wasi/api.h> |
320054e8 DG |
11 | #include <errno.h> |
12 | ||
446cb3f1 | 13 | #ifdef __wasilibc_unmodified_upstream // generated constant names |
320054e8 DG |
14 | static_assert(SHUT_RD == __WASI_SHUT_RD, "Value mismatch"); |
15 | static_assert(SHUT_WR == __WASI_SHUT_WR, "Value mismatch"); | |
446cb3f1 DG |
16 | #else |
17 | static_assert(SHUT_RD == __WASI_SDFLAGS_RD, "Value mismatch"); | |
18 | static_assert(SHUT_WR == __WASI_SDFLAGS_WR, "Value mismatch"); | |
19 | #endif | |
320054e8 DG |
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 | } |