Rune Serialize - Stabilization, Generation, major overhaul
[rune.git] / classes / sys / sys.d
1 # SYS/SYS.D - Misc internalized support (for speed)
2 #
3
4 public class Sys {
5         #%doc
6         #
7         # The bcopy we all know and love, with bounds-checking and cast
8         # limitations (you can't synthesize structures containing lvalues,
9         # pointers, or references with it).
10         #
11         public internal void bcopy(const void *s, void *d, size_t);
12
13         #%doc
14         #
15         # This issues the C exit(), killing the process and all of its
16         # theads.
17         #
18         public internal void exit(int code);
19
20         #%
21         #
22         # This terminates the program, killing the process and all of its
23         # theads, and core-dumping if DebugOpt is set in the runtime.
24         #
25         public internal void abort();
26
27         #%doc
28         #
29         # Execs a program.  Rune provides a number of additional helper
30         # functions (written in Rune) for other forms.  Rune will automatically
31         # clear O_CLOEXEC on descriptors 0, 1, and 2.  Any other descriptors
32         # will depend on their O_CLOEXEC status.  Note that by default any
33         # new descriptors opened by a Rune program set O_CLOEXEC by default.
34         #
35         #public internal int execve(const char *path,
36         #                               const char **argv, const char **envp);
37
38         #%doc
39         #
40         # Get or modify the current environment.  Similar to the C calls
41         # but setenv() always overwrites.
42         #
43         public internal char *getenv(const char *name);
44         public internal void setenv(const char *name, const char *value);
45         public internal int unsetenv(const char *name);
46 }
47
48 global int inpanic;
49
50 public void
51 Sys.panic(const char *ctl, ...)
52 {
53         Fs fs;
54
55 # XXX implement va_list and ... passing.
56 #       if (inpanic)
57 #               abort();
58 #       inpanic = 1;
59         fs.setfd(2);
60         fs.write(ctl, Str.strlen(ctl));
61         fs.write("\n", 1);
62         abort();
63 }