Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated for Rust 0.2

  • Loading branch information...
commit 3a53ff75c19c4afe4a39295f5fc330c4edad277c 1 parent 7358215
@juturnas juturnas authored committed
Showing with 6 additions and 8 deletions.
  1. +6 −8 errno.rs
View
14 errno.rs
@@ -22,13 +22,11 @@
use std; // required by the tests
-import size_t = ctypes::size_t;
-import c_int = ctypes::c_int;
-import sbuf = str::sbuf;
+import libc::{size_t, c_int};
#[nolink]
native mod __glibc {
- fn __xpg_strerror_r(errnum: c_int, buf: *mutable u8, len: size_t) -> c_int;
+ fn __xpg_strerror_r(errnum: c_int, buf: *libc::c_char, len: size_t) -> c_int;
fn __errno_location() -> *c_int;
}
@@ -37,18 +35,18 @@ fn errno() -> int {
}
fn strerror(errnum: int) -> str {
- let bufv = vec::init_elt_mut(1024u, 0u8);
- let buf = ptr::mut_addr_of(bufv[0]);
+ let bufv = vec::from_elem(1024u, 0u8);
let len = vec::len(bufv);
unsafe {
- let r = __glibc::__xpg_strerror_r(errnum as c_int, buf, len as size_t);
+ let buf : *libc::c_char = ::unsafe::reinterpret_cast(bufv);
+ let r =__glibc::__xpg_strerror_r(errnum as c_int, buf, len as size_t);
if (r as bool) {
fail #fmt("__glibc::__xpg_strerror_r() failed [errno=%d]", errno());
}
- ret str::from_cstr(buf as sbuf);
+ str::unsafe::from_c_str(buf)
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.