Skip to content

Instantly share code, notes, and snippets.

@alexcrichton
Created April 19, 2014 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexcrichton/11071346 to your computer and use it in GitHub Desktop.
Save alexcrichton/11071346 to your computer and use it in GitHub Desktop.
#![feature(phase)]
#[phase(syntax)] extern crate green;
use std::io;
#[cfg(green)]
green_start!(main)
fn main() {
println!("------------------ before");
print();
io::stdin();
println!("------------------ after");
print();
}
fn print() {
extern {
fn fcntl(fd: i32, cmd: i32, ...) -> i32;
}
println!("stdin O_NONBLOCK: {}", unsafe { fcntl(0, 3) & 0o00004000 });
println!("stdout O_NONBLOCK: {}", unsafe { fcntl(1, 3) & 0o00004000 });
}
$ rustc foo.rs --cfg green -o green
$ rustc foo.rs -o native
$ ./green
------------------ before
stdin O_NONBLOCK: 0
stdout O_NONBLOCK: 0
------------------ after
stdin O_NONBLOCK: 2048
stdout O_NONBLOCK: 2048
$ ./native
------------------ before
stdin O_NONBLOCK: 0
stdout O_NONBLOCK: 0
------------------ after
stdin O_NONBLOCK: 0
stdout O_NONBLOCK: 0
$ ./native && ./green
------------------ before
stdin O_NONBLOCK: 0
stdout O_NONBLOCK: 0
------------------ after
stdin O_NONBLOCK: 0
stdout O_NONBLOCK: 0
------------------ before
stdin O_NONBLOCK: 0
stdout O_NONBLOCK: 0
------------------ after
stdin O_NONBLOCK: 2048
stdout O_NONBLOCK: 2048
$ ./green && ./native
------------------ before
stdin O_NONBLOCK: 0
stdout O_NONBLOCK: 0
------------------ after
stdin O_NONBLOCK: 2048
stdout O_NONBLOCK: 2048
------------------ before
stdin O_NONBLOCK: 2048
stdout O_NONBLOCK: 2048
------------------ after
stdin O_NONBLOCK: 2048
stdout O_NONBLOCK: 2048
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment