]> git.proxmox.com Git - wasi-libc.git/blame - libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c
WASI libc prototype implementation.
[wasi-libc.git] / libc-bottom-half / cloudlibc / src / libc / sys / socket / shutdown.c
CommitLineData
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>
10#include <wasi/core.h>
11#include <errno.h>
12
13static_assert(SHUT_RD == __WASI_SHUT_RD, "Value mismatch");
14static_assert(SHUT_WR == __WASI_SHUT_WR, "Value mismatch");
15
16int shutdown(int socket, int how) {
17 // Validate shutdown flags.
18 if (how != SHUT_RD && how != SHUT_WR && how != SHUT_RDWR) {
19 errno = EINVAL;
20 return -1;
21 }
22
23 __wasi_errno_t error = __wasi_sock_shutdown(socket, how);
24 if (error != 0) {
25 errno = errno_fixup_socket(socket, error);
26 return -1;
27 }
28 return error;
29}