impl: add {pre,post}_assert statements
[m6w6/ext-psi] / psi.d / netdb.psi
1 function psi\endhostent() : void {
2 return void(endhostent);
3 }
4 function psi\endnetend() : void {
5 return void(endnetent);
6 }
7 function psi\endprotoent() : void {
8 return void(endprotoent);
9 }
10 function psi\endservent() : void {
11 return void(endservent);
12 }
13
14 function psi\sethostent(bool $stayopen) : void {
15 let stayopen = intval($stayopen);
16 return void(sethostent);
17 }
18 function psi\setnetset(bool $stayopen) : void {
19 let stayopen = intval($stayopen);
20 return void(setnetent);
21 }
22 function psi\setprotoent(bool $stayopen) : void {
23 let stayopen = intval($stayopen);
24 return void(setprotoent);
25 }
26 function psi\setservent(bool $stayopen) : void {
27 let stayopen = intval($stayopen);
28 return void(setservent);
29 }
30
31 function psi\gethostent() : array {
32 return to_array(*gethostent,
33 to_string(h_name),
34 to_array(h_aliases, to_string(h_aliases)),
35 to_int(h_addrtype),
36 to_int(h_length),
37 to_array(h_addr_list, to_string(h_addr_list, h_length))
38 );
39 }
40
41 function psi\gai_strerror(int $errcode) : string {
42 let errcode = intval($errcode);
43 return to_string(gai_strerror);
44 }
45
46 // extern int getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res)
47 function psi\getaddrinfo(string $node, string $service, array $hints = NULL, object &$res = NULL) : int {
48 let node = strval($node);
49 let service = strval($service);
50 let hints = &arrval($hints,
51 intval($ai_flags),
52 intval($ai_family),
53 intval($ai_socktype),
54 intval($ai_protocol)
55 );
56 let res = &NULL;
57 return to_int(getaddrinfo);
58 set $res = to_array(**res,
59 to_int(ai_flags),
60 to_int(ai_family),
61 to_int(ai_socktype),
62 to_int(ai_protocol),
63 to_int(ai_addrlen),
64 to_string(ai_addr, ai_addrlen),
65 to_string(ai_canonname),
66 to_array(*ai_next, ...)
67 );
68 free freeaddrinfo(*res);
69 }
70
71 // extern int getnameinfo(struct sockaddr *sa, socklen_t salen, char *host, socklen_t hostlen, char *serv, socklen_t servlen, int flags)
72 function psi\getnameinfo(string $addr, string &$host = NULL, string &$service = NULL, int $flags = 0) : int {
73 let sa = strval($addr);
74 let salen = strlen($addr);
75 let hostlen = psi\NI_MAXHOST;
76 let host = calloc(hostlen, psi\SIZEOF_CHAR);
77 let servlen = psi\NI_MAXSERV;
78 let serv = calloc(servlen, psi\SIZEOF_CHAR);
79 let flags = intval($flags);
80 return to_int(getnameinfo);
81 set $host = to_string(host);
82 set $service = to_string(serv);
83 }