custom message type for VM_QUERY_EXIT
[minix3.git] / lib / libc / sys-minix / shutdown.c
blob001a6a24466eeddd6f0b638023f1f06baf7c0d97
1 #include <sys/cdefs.h>
2 #include "namespace.h"
4 #include <errno.h>
5 #include <stdio.h>
6 #include <sys/ioctl.h>
7 #include <sys/socket.h>
8 #include <sys/un.h>
10 #include <net/gen/in.h>
11 #include <net/gen/tcp.h>
12 #include <net/gen/tcp_io.h>
14 #define DEBUG 0
16 static int _tcp_shutdown(int sock, int how);
17 static int _uds_shutdown(int sock, int how);
19 int shutdown(int sock, int how)
21 int r;
22 struct sockaddr_un uds_addr;
23 nwio_tcpconf_t tcpconf;
25 r= ioctl(sock, NWIOGTCPCONF, &tcpconf);
26 if (r != -1 || errno != ENOTTY)
28 if (r == -1)
30 /* Bad file descriptor */
31 return -1;
33 return _tcp_shutdown(sock, how);
36 r= ioctl(sock, NWIOGUDSADDR, &uds_addr);
37 if (r != -1 || errno != ENOTTY)
39 if (r == -1)
41 /* Bad file descriptor */
42 return -1;
44 return _uds_shutdown(sock, how);
47 #if DEBUG
48 fprintf(stderr, "shutdown: not implemented for fd %d\n", sock);
49 #endif
50 errno= ENOSYS;
51 return -1;
54 static int _tcp_shutdown(int sock, int how)
56 int r;
58 if (how == SHUT_WR || how == SHUT_RDWR)
60 r= ioctl(sock, NWIOTCPSHUTDOWN, NULL);
61 if (r == -1)
62 return -1;
63 if (how == SHUT_WR)
64 return 0;
67 /* We can't shutdown the read side of the socket. */
68 errno= ENOSYS;
69 return -1;
72 static int _uds_shutdown(int sock, int how)
74 return ioctl(sock, NWIOSUDSSHUT, &how);