some coverity fixes.
[minix.git] / lib / libc / sys-minix / shutdown.c
blob3f86cc51660bd570f4dc47bdd0b06f6bfe7560ab
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 #ifdef __weak_alias
15 __weak_alias(shutdown, _shutdown)
16 #endif
18 #define DEBUG 0
20 static int _tcp_shutdown(int sock, int how);
21 static int _uds_shutdown(int sock, int how);
23 int shutdown(int sock, int how)
25 int r;
26 struct sockaddr_un uds_addr;
27 nwio_tcpconf_t tcpconf;
29 r= ioctl(sock, NWIOGTCPCONF, &tcpconf);
30 if (r != -1 || (errno != ENOTTY && errno != EBADIOCTL))
32 if (r == -1)
34 /* Bad file descriptor */
35 return -1;
37 return _tcp_shutdown(sock, how);
40 r= ioctl(sock, NWIOGUDSADDR, &uds_addr);
41 if (r != -1 || (errno != ENOTTY && errno != EBADIOCTL))
43 if (r == -1)
45 /* Bad file descriptor */
46 return -1;
48 return _uds_shutdown(sock, how);
51 #if DEBUG
52 fprintf(stderr, "shutdown: not implemented for fd %d\n", sock);
53 #endif
54 errno= ENOSYS;
55 return -1;
58 static int _tcp_shutdown(int sock, int how)
60 int r;
62 if (how == SHUT_WR || how == SHUT_RDWR)
64 r= ioctl(sock, NWIOTCPSHUTDOWN, NULL);
65 if (r == -1)
66 return -1;
67 if (how == SHUT_WR)
68 return 0;
71 /* We can't shutdown the read side of the socket. */
72 errno= ENOSYS;
73 return -1;
76 static int _uds_shutdown(int sock, int how)
78 return ioctl(sock, NWIOSUDSSHUT, &how);