Stop using snprintf in write_hex_to_fd (XCC)
[akaros.git] / tools / compilers / gcc-glibc / glibc-2.19-akaros / sysdeps / akaros / getsockopt.c
1 /* Copyright (c) 2015 Google, Inc.
2  * Barret Rhoden <brho@cs.berkeley.edu>
3  * See LICENSE for details. */
4
5 #include <errno.h>
6 #include <sys/socket.h>
7
8 #include <sys/plan9_helpers.h>
9
10 static int sol_socket_gso(Rock *r, int optname, void *optval, socklen_t *optlen)
11 {
12         switch (optname) {
13                 case (SO_TYPE):
14                         if (*optlen < 4) {
15                                 __set_errno(EINVAL);
16                                 return -1;
17                         }
18                         *(int*)optval = r->stype;
19                         *optlen = 4;
20                         break;
21                 case (SO_ERROR):
22                         *(int*)optval = 0;
23                         *optlen = 4;
24                         break;
25                 default:
26                         __set_errno(ENOPROTOOPT);
27                         return -1;
28         };
29         return 0;
30 }
31
32 int __getsockopt(int sockfd, int level, int optname, void *optval,
33                  socklen_t *optlen)
34 {
35         Rock *r = _sock_findrock(sockfd, 0);
36         if (!r) {
37                 /* could be EBADF too, we can't tell */
38                 __set_errno(ENOTSOCK);
39                 return -1;
40         }
41         switch (level) {
42                 case (SOL_SOCKET):
43                         return sol_socket_gso(r, optname, optval, optlen);
44                 default:
45                         __set_errno(ENOPROTOOPT);
46                         return -1;
47         };
48 }
49 weak_alias(__getsockopt, getsockopt)