extern crate libc;

use libc::funcs::posix88::unistd::getlogin;
use std::c_str::CString;
use std::os;


fn main() {
    let login = unsafe {
        CString::new(
            getlogin() as *const libc::c_char,
            false
        )
    };

    match login.as_str() {
        Some(username) => println!("{}", username),
        None => os::set_exit_status(1),
    }
}

extern crate libc;

use libc::funcs::posix88::unistd::getlogin;
use std::c_str::CString;
use std::os;


fn main() {
    unsafe {

        let login_c = getlogin() as *const libc::c_char;
        let login = CString::new(login_c, false);

        match login.as_str() {
            Some(username) => println!("{}", username),
            None => os::set_exit_status(1),
        }

    }
}

--- 
+++ 
@@ -6,15 +6,15 @@
 
 
 fn main() {
-    let login = unsafe {
-        CString::new(
-            getlogin() as *const libc::c_char,
-            false
-        )
-    };
+    unsafe {
 
-    match login.as_str() {
-        Some(username) => println!("{}", username),
-        None => os::set_exit_status(1),
+        let login_c = getlogin() as *const libc::c_char;
+        let login = CString::new(login_c, false);
+
+        match login.as_str() {
+            Some(username) => println!("{}", username),
+            None => os::set_exit_status(1),
+        }
+
     }
 }
Move code outside of unsafe block
