]> git.lizzy.rs Git - rust.git/blob - src/rt/rust_run_program.cpp
Convert most of rust_run_program.cpp to rust (issue #2674).
[rust.git] / src / rt / rust_run_program.cpp
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11
12 #include "rust_kernel.h"
13
14 #ifdef __APPLE__
15 #include <crt_externs.h>
16 #endif
17
18 #if defined(__WIN32__)
19
20 extern "C" CDECL void
21 rust_unset_sigprocmask() {
22     // empty stub for windows to keep linker happy
23 }
24
25 extern "C" CDECL void
26 rust_set_environ(void* envp) {
27     // empty stub for windows to keep linker happy
28 }
29
30 #elif defined(__GNUC__)
31
32 #include <signal.h>
33 #include <unistd.h>
34
35 #ifdef __FreeBSD__
36 extern char **environ;
37 #endif
38
39 extern "C" CDECL void
40 rust_unset_sigprocmask() {
41     // this can't be safely converted to rust code because the
42     // representation of sigset_t is platform-dependent
43     sigset_t sset;
44     sigemptyset(&sset);
45     sigprocmask(SIG_SETMASK, &sset, NULL);
46 }
47
48 extern "C" CDECL void
49 rust_set_environ(void* envp) {
50     // FIXME: this could actually be converted to rust (see issue #2674)
51 #ifdef __APPLE__
52     *_NSGetEnviron() = (char **) envp;
53 #else
54     environ = (char **) envp;
55 #endif
56 }
57
58 #else
59 #error "Platform not supported."
60 #endif
61
62 //
63 // Local Variables:
64 // mode: C++
65 // fill-column: 78;
66 // indent-tabs-mode: nil
67 // c-basic-offset: 4
68 // buffer-file-coding-system: utf-8-unix
69 // compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
70 // End:
71 //