blob: 1c311a8f3a8abddfe79869b1e9dbc85afce7764e (
plain)
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
|
package libc_tests
import "core:c/libc"
test_stdio :: proc() {
c: libc.char = 'C';
libc.puts("Hello from puts");
libc.printf("Hello from printf in %c\n", c);
}
test_thread :: proc() {
thread_proc :: proc "c" (rawptr) -> libc.int {
libc.printf("Hello from thread");
return 42;
}
thread: libc.thrd_t;
libc.thrd_create(&thread, thread_proc, nil);
result: libc.int;
libc.thrd_join(thread, &result);
libc.printf(" %d\n", result);
}
jmp: libc.jmp_buf;
test_sjlj :: proc() {
if libc.setjmp(&jmp) != 0 {
libc.printf("Hello from longjmp\n");
return;
}
libc.printf("Hello from setjmp\n");
libc.longjmp(&jmp, 1);
}
test_signal :: proc() {
handler :: proc "c" (sig: libc.int) {
libc.printf("Hello from signal handler\n");
}
libc.signal(libc.SIGABRT, handler);
libc.raise(libc.SIGABRT);
}
test_atexit :: proc() {
handler :: proc "c" () {
libc.printf("Hello from atexit\n");
}
libc.atexit(handler);
}
main :: proc() {
test_stdio();
test_thread();
test_sjlj();
test_signal();
test_atexit();
}
|