Fun
0.41.5
The programming language that makes You have fun
Main Page
Data Structures
Files
File List
Globals
Loading...
Searching...
No Matches
src
vm
os
fd_set_nonblock.c
Go to the documentation of this file.
1
/*
2
* This file is part of the Fun programming language.
3
* https://fun-lang.xyz/
4
*
5
* Copyright 2026 Johannes Findeisen <you@hanez.org>
6
* Licensed under the terms of the Apache-2.0 license.
7
* https://opensource.org/license/apache-2-0
8
*/
9
21
22
case
OP_FD_SET_NONBLOCK
: {
23
/* Pops on:int (0/1), fd:int; pushes 1 on success, 0 on error/unsupported */
24
Value
onv
= pop_value(vm);
25
Value
fdv
= pop_value(vm);
26
int
ok
= 0;
27
#ifdef __unix__
28
if
(
fdv
.type !=
VAL_INT
||
onv
.type !=
VAL_INT
) {
29
fprintf
(stderr,
"Runtime type error: fd_set_nonblock expects (int fd, int on)\n"
);
30
ok
= 0;
31
}
else
{
32
int
fd
= (int)
fdv
.i;
33
int
on = (int)
onv
.i;
34
int
flags = fcntl(
fd
, F_GETFL, 0);
35
if
(flags >= 0) {
36
if
(on)
37
flags |= O_NONBLOCK;
38
else
39
flags &= ~O_NONBLOCK;
40
if
(fcntl(
fd
, F_SETFL, flags) == 0)
ok
= 1;
41
}
42
}
43
#else
44
(void)
onv
; (void)
fdv
;
45
#endif
46
free_value
(
onv
);
47
free_value
(
fdv
);
48
push_value
(vm,
make_int
(
ok
? 1 : 0));
49
break
;
50
}
OP_FD_SET_NONBLOCK
@ OP_FD_SET_NONBLOCK
Definition
bytecode.h:230
ok
int ok
Definition
contains.c:38
fdv
Value fdv
Definition
fd_poll_read.c:25
push_value
push_value(vm, make_int(ok ? 1 :0))
free_value
free_value(onv)
onv
void onv
Definition
fd_set_nonblock.c:44
fd
int fd
Definition
serial_open.c:92
Value
Tagged union representing a Fun value.
Definition
value.h:68
make_int
Value make_int(int64_t v)
Construct a Value representing a 64-bit integer.
Definition
value.c:51
VAL_INT
@ VAL_INT
Definition
value.h:51
fprintf
#define fprintf
Definition
vm.c:200
Generated on
for Fun by
1.16.1