Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/wapython
Path: blob/main/core/posix-wasm/src/posix-wasm.c
1067 views
1
#include "posix-wasm.h"
2
#include "public.h"
3
4
// These two are missing from zig's libc for some reason. I don't think
5
// it is possible to express these in ziglang either.
6
#include <stdarg.h>
7
#include <stdio.h>
8
int fiprintf(FILE * stream, const char * format, ...) {
9
va_list va;
10
va_start(va, format);
11
int d = vfprintf(stream, format, va);
12
va_end(va);
13
return d;
14
}
15
PUBLIC(fiprintf)
16
17
int __small_fprintf(FILE * stream, const char * format, ...) {
18
va_list va;
19
va_start(va, format);
20
int d = vfprintf(stream, format, va);
21
va_end(va);
22
return d;
23
}
24
PUBLIC(__small_fprintf)
25
26
int siprintf(char * s, const char * format, ...) {
27
va_list va;
28
va_start(va, format);
29
int d = vsprintf(s, format, va);
30
va_end(va);
31
return d;
32
}
33
PUBLIC(siprintf)
34
35
#include <signal.h>
36
// It is important to define this function to actually do something, rather
37
// than be a pure stub function, in the case we are asking for what the
38
// signal handler is. This is requested in Python's PyOS_getsig, and if
39
// we just don't set it, then the handler is considered random nonsense.
40
// That's not good, since then the proper handlers from python, e.g., the
41
// one for sigint, don't get setup in Python's signal_get_set_handlers function.
42
int sigaction(int signum, const struct sigaction *restrict act,
43
struct sigaction *restrict oldact) {
44
if(act == NULL && oldact != NULL) { // getting the signal info.
45
oldact->sa_handler = SIG_DFL; // only this matters for python
46
oldact->sa_mask = 0;
47
oldact->sa_flags = 0;
48
}
49
return 0;
50
}
51
52