1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-25 09:47:17 +00:00

Cleanup code a bit

Inconsistent indentation and such fixed, superfluous newlines removed,
documentation of new functions.
This commit is contained in:
llmII 2021-09-06 18:30:54 -05:00
parent 8c938ceff9
commit 1597ca0de5
No known key found for this signature in database
GPG Key ID: E3AD2E259F58A9A0

View File

@ -576,23 +576,18 @@ JANET_CORE_FN(cfun_net_listen,
#define SO_MIN(a, b) (((a) < (b))? (a) : (b)) #define SO_MIN(a, b) (((a) < (b))? (a) : (b))
#define SA_ADDRSTRLEN SO_MAX(INET6_ADDRSTRLEN, (sizeof ((struct sockaddr_un *)0)->sun_path) + 1) #define SA_ADDRSTRLEN SO_MAX(INET6_ADDRSTRLEN, (sizeof ((struct sockaddr_un *)0)->sun_path) + 1)
#define sa_ntoa(sa) sa_ntoa_((char [SA_ADDRSTRLEN]){ 0 }, SA_ADDRSTRLEN, (sa)) #define sa_ntoa(sa) sa_ntoa_((char [SA_ADDRSTRLEN]){ 0 }, SA_ADDRSTRLEN, (sa))
#define sa_aton(str) sa_aton_(&(struct sockaddr_storage){ 0 }, sizeof (struct sockaddr_storage), (str))
#define sa_family(...) sa_family(__VA_ARGS__) #define sa_family(...) sa_family(__VA_ARGS__)
#define sa_port(...) sa_port(__VA_ARGS__) #define sa_port(...) sa_port(__VA_ARGS__)
union sockaddr_arg { union sockaddr_arg {
struct sockaddr *sa; struct sockaddr *sa;
const struct sockaddr *c_sa; const struct sockaddr *c_sa;
struct sockaddr_storage *ss; struct sockaddr_storage *ss;
struct sockaddr_storage *c_ss; struct sockaddr_storage *c_ss;
struct sockaddr_in *sin; struct sockaddr_in *sin;
struct sockaddr_in *c_sin; struct sockaddr_in *c_sin;
struct sockaddr_in6 *sin6; struct sockaddr_in6 *sin6;
struct sockaddr_in6 *c_sin6; struct sockaddr_in6 *c_sin6;
struct sockaddr_un *sun; struct sockaddr_un *sun;
struct sockaddr_un *c_sun; struct sockaddr_un *c_sun;
union sockaddr_any *any; union sockaddr_any *any;
@ -611,7 +606,9 @@ union sockaddr_any {
}; };
static inline union sockaddr_arg sockaddr_ref(void *arg) { static inline union sockaddr_arg sockaddr_ref(void *arg) {
return (union sockaddr_arg){ arg }; return (union sockaddr_arg) {
arg
};
} }
static inline sa_family_t *(sa_family)(void *arg) { static inline sa_family_t *(sa_family)(void *arg) {
@ -708,18 +705,12 @@ error:
return (char *)def; return (char *)def;
} }
void *sa_pton(void *, size_t, const char *, const void *, int *);
static inline char *sa_ntoa_(char *dst, size_t lim, const void *src) { static inline char *sa_ntoa_(char *dst, size_t lim, const void *src) {
return sa_ntop(dst, lim, src, NULL, &(int){ 0 }), dst; return sa_ntop(dst, lim, src, NULL, &(int) {
0
}), dst;
} }
/*
static inline void *sa_aton_(void *dst, size_t lim, const char *src) {
return sa_pton(dst, lim, src, NULL, &(int){ 0 }), dst;
}
*/
static Janet janet_so_getname(const struct sockaddr_storage *ss, socklen_t slen) { static Janet janet_so_getname(const struct sockaddr_storage *ss, socklen_t slen) {
uint8_t *hn = NULL; uint8_t *hn = NULL;
uint16_t hp = 0; uint16_t hp = 0;
@ -773,7 +764,7 @@ static Janet janet_so_getname(const struct sockaddr_storage *ss, socklen_t slen)
JANET_CORE_FN(cfun_net_getsockname, JANET_CORE_FN(cfun_net_getsockname,
"(net/localname stream)", "(net/localname stream)",
"Document me!") { "Gets the local address and port in a tuple in that order.") {
janet_arity(argc, 1, 1); janet_arity(argc, 1, 1);
JanetStream *js = janet_getabstract(argv, 0, &janet_stream_type); JanetStream *js = janet_getabstract(argv, 0, &janet_stream_type);
struct sockaddr_storage ss; struct sockaddr_storage ss;
@ -790,7 +781,7 @@ JANET_CORE_FN(cfun_net_getsockname,
JANET_CORE_FN(cfun_net_getpeername, JANET_CORE_FN(cfun_net_getpeername,
"(net/peername stream)", "(net/peername stream)",
"Document me!") { "Gets the remote peer's address and port in a tuple in that order.") {
janet_arity(argc, 1, 1); janet_arity(argc, 1, 1);
JanetStream *js = janet_getabstract(argv, 0, &janet_stream_type); JanetStream *js = janet_getabstract(argv, 0, &janet_stream_type);
struct sockaddr_storage ss; struct sockaddr_storage ss;