tutorial: Fix types in gettimeofday example. Closes #1657
This commit is contained in:
parent
5e250b6951
commit
6d360d2b02
1 changed files with 5 additions and 3 deletions
|
@ -2334,17 +2334,19 @@ microsecond-resolution timer.
|
||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
use std;
|
use std;
|
||||||
type timeval = {mutable tv_sec: u32,
|
type timeval = {mutable tv_sec: uint,
|
||||||
mutable tv_usec: u32};
|
mutable tv_usec: uint};
|
||||||
#[nolink]
|
#[nolink]
|
||||||
native mod libc {
|
native mod libc {
|
||||||
fn gettimeofday(tv: *timeval, tz: *()) -> i32;
|
fn gettimeofday(tv: *timeval, tz: *()) -> i32;
|
||||||
}
|
}
|
||||||
fn unix_time_in_microseconds() -> u64 unsafe {
|
fn unix_time_in_microseconds() -> u64 unsafe {
|
||||||
let x = {mutable tv_sec: 0u32, mutable tv_usec: 0u32};
|
let x = {mutable tv_sec: 0u, mutable tv_usec: 0u};
|
||||||
libc::gettimeofday(ptr::addr_of(x), ptr::null());
|
libc::gettimeofday(ptr::addr_of(x), ptr::null());
|
||||||
ret (x.tv_sec as u64) * 1000_000_u64 + (x.tv_usec as u64);
|
ret (x.tv_sec as u64) * 1000_000_u64 + (x.tv_usec as u64);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# fn main() { assert #fmt("%?", unix_time_in_microseconds()) != ""; }
|
||||||
~~~~
|
~~~~
|
||||||
|
|
||||||
The `#[nolink]` attribute indicates that there's no native library to link
|
The `#[nolink]` attribute indicates that there's no native library to link
|
||||||
|
|
Loading…
Reference in a new issue