1
0
Fork 0
forked from fun/fun

Fixed the code style in *.c files to two spaces indentation and add a linter named funstx to Fun. (0.39.0)

This commit is contained in:
Johannes Findeisen 2026-03-18 20:52:00 +01:00
commit 03b2532474
237 changed files with 17550 additions and 13911 deletions

View file

@ -10,41 +10,44 @@
*/
case OP_SOCK_TCP_CONNECT: {
/* Pops port, host; pushes fd (>0) or 0 */
Value portv = pop_value(vm);
Value hostv = pop_value(vm);
int fd = 0;
/* Pops port, host; pushes fd (>0) or 0 */
Value portv = pop_value(vm);
Value hostv = pop_value(vm);
int fd = 0;
#ifdef __unix__
if (hostv.type != VAL_STRING || portv.type != VAL_INT) {
fprintf(stderr, "Runtime type error: tcp_connect expects (string host, int port)\n");
free_value(portv);
free_value(hostv);
push_value(vm, make_int(0));
break;
}
char *host = value_to_string_alloc(&hostv);
int port = (int)portv.i;
if (host) {
char portstr[16];
snprintf(portstr, sizeof(portstr), "%d", port);
struct addrinfo hints, *res = NULL, *rp;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
if (getaddrinfo(host, portstr, &hints, &res) == 0) {
for (rp = res; rp != NULL; rp = rp->ai_next) {
int s = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
if (s < 0) continue;
if (connect(s, rp->ai_addr, rp->ai_addrlen) == 0) { fd = s; break; }
close(s);
}
if (res) freeaddrinfo(res);
}
free(host);
}
#endif
if (hostv.type != VAL_STRING || portv.type != VAL_INT) {
fprintf(stderr, "Runtime type error: tcp_connect expects (string host, int port)\n");
free_value(portv);
free_value(hostv);
push_value(vm, make_int(fd > 0 ? fd : 0));
push_value(vm, make_int(0));
break;
}
char *host = value_to_string_alloc(&hostv);
int port = (int)portv.i;
if (host) {
char portstr[16];
snprintf(portstr, sizeof(portstr), "%d", port);
struct addrinfo hints, *res = NULL, *rp;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
if (getaddrinfo(host, portstr, &hints, &res) == 0) {
for (rp = res; rp != NULL; rp = rp->ai_next) {
int s = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
if (s < 0) continue;
if (connect(s, rp->ai_addr, rp->ai_addrlen) == 0) {
fd = s;
break;
}
close(s);
}
if (res) freeaddrinfo(res);
}
free(host);
}
#endif
free_value(portv);
free_value(hostv);
push_value(vm, make_int(fd > 0 ? fd : 0));
break;
}