]> git.proxmox.com Git - wasi-libc.git/blob - libc-bottom-half/sources/socket.c
Use the same indentation style as surrounding code.
[wasi-libc.git] / libc-bottom-half / sources / socket.c
1 #include <errno.h>
2 #include <fcntl.h>
3 #include <assert.h>
4 #include <sys/socket.h>
5
6 static_assert((SOCK_DGRAM & ~SOCK_NONBLOCK & ~SOCK_CLOEXEC) == SOCK_DGRAM,
7 "Socket type flags clash");
8 static_assert((SOCK_STREAM & ~SOCK_NONBLOCK & ~SOCK_CLOEXEC) == SOCK_STREAM,
9 "Socket type flags clash");
10
11 static int socketcall(int domain, int type, int protocol) {
12 // FIXME: Implement socket by looking up pre-opened network sockets.
13 errno = ENOSYS;
14 return -1;
15 }
16
17 int socket(int domain, int type, int protocol)
18 {
19 int s = socketcall(domain, type & ~SOCK_CLOEXEC & ~SOCK_NONBLOCK, protocol);
20 if (s < 0) return s;
21 if (type & SOCK_CLOEXEC) fcntl(s, F_SETFD, FD_CLOEXEC);
22 if (type & SOCK_NONBLOCK) fcntl(s, F_SETFL, O_NONBLOCK);
23 return s;
24 }