-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathgetsockopt.c
More file actions
80 lines (68 loc) · 1.45 KB
/
Copy pathgetsockopt.c
File metadata and controls
80 lines (68 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* getsockopt() emulation for MiNT-Net, (w) '93, kay roemer
*/
#include <errno.h>
#include <mint/mintbind.h>
#include <sys/socket.h>
#include "mintsock.h"
#include "sockets_global.h"
__typeof__(getsockopt) __getsockopt;
int
__getsockopt (int fd, int level, int optname, void *optval, socklen_t *optlen)
{
if (__libc_newsockets) {
long r = Fgetsockopt (fd, level, optname, optval, optlen);
if (r != -ENOSYS) {
if (r < 0) {
__set_errno (-r);
return -1;
}
/*
* kernel reports negative error codes,
* but applications expect positive codes just like for errno
*/
if (optval && optlen && level == SOL_SOCKET && optname == SO_ERROR)
{
if (*optlen == sizeof(short))
{
short *p = optval;
if (*p < 0)
*p = -(*p);
} else if (*optlen == sizeof(char))
{
signed char *p = optval;
if (*p < 0)
*p = -(*p);
} else if (*optlen == sizeof(long))
{
long *p = optval;
if (*p < 0)
*p = -(*p);
}
}
return 0;
} else
__libc_newsockets = 0;
}
{
struct getsockopt_cmd cmd;
long optlen32;
int r;
if (optlen)
optlen32 = *optlen;
cmd.cmd = GETSOCKOPT_CMD;
cmd.level = level;
cmd.optname = optname;
cmd.optval = optval;
cmd.optlen = &optlen32;
r = Fcntl (fd, (long) &cmd, SOCKETCALL);
if (optlen)
*optlen = optlen32;
if (r < 0) {
__set_errno (-r);
return -1;
}
return 0;
}
}
weak_alias (__getsockopt, getsockopt)