Răsfoiți Sursa

Fix warnings

Jeremy Soller 6 ani în urmă
părinte
comite
a5279b648f

+ 5 - 5
src/header/stdio/ext.rs

@@ -3,21 +3,21 @@ use platform::types::*;
 
 #[no_mangle]
 pub extern "C" fn __fpending(stream: *mut FILE) -> size_t {
-    let mut stream = unsafe { &mut *stream }.lock();
+    let stream = unsafe { &mut *stream }.lock();
 
     stream.writer.inner.buf.len() as size_t
 }
 
 #[no_mangle]
 pub extern "C" fn __freadable(stream: *mut FILE) -> c_int {
-    let mut stream = unsafe { &mut *stream }.lock();
+    let stream = unsafe { &mut *stream }.lock();
 
     (stream.flags & F_NORD == 0) as c_int
 }
 
 #[no_mangle]
 pub extern "C" fn __fwritable(stream: *mut FILE) -> c_int {
-    let mut stream = unsafe { &mut *stream }.lock();
+    let stream = unsafe { &mut *stream }.lock();
 
     (stream.flags & F_NOWR == 0) as c_int
 }
@@ -25,7 +25,7 @@ pub extern "C" fn __fwritable(stream: *mut FILE) -> c_int {
 //TODO: Check last operation when read-write
 #[no_mangle]
 pub extern "C" fn __freading(stream: *mut FILE) -> c_int {
-    let mut stream = unsafe { &mut *stream }.lock();
+    let stream = unsafe { &mut *stream }.lock();
 
     (stream.flags & F_NORD == 0) as c_int
 }
@@ -33,7 +33,7 @@ pub extern "C" fn __freading(stream: *mut FILE) -> c_int {
 //TODO: Check last operation when read-write
 #[no_mangle]
 pub extern "C" fn __fwriting(stream: *mut FILE) -> c_int {
-    let mut stream = unsafe { &mut *stream }.lock();
+    let stream = unsafe { &mut *stream }.lock();
 
     (stream.flags & F_NOWR == 0) as c_int
 }

+ 6 - 2
src/header/stdlib/mod.rs

@@ -451,7 +451,7 @@ where
 #[no_mangle]
 pub extern "C" fn mktemp(name: *mut c_char) -> *mut c_char {
     if inner_mktemp(name, 0, || unsafe {
-        let name = unsafe { CStr::from_ptr(name) };
+        let name = CStr::from_ptr(name);
         let ret = if Sys::access(name, 0) != 0 && platform::errno == ENOENT {
             Some(())
         } else {
@@ -868,6 +868,8 @@ pub unsafe extern "C" fn strtoll(
 
 #[no_mangle]
 pub unsafe extern "C" fn system(command: *const c_char) -> c_int {
+    //TODO: share code with popen
+
     let child_pid = unistd::fork();
     if child_pid == 0 {
         let command_nonnull = if command.is_null() {
@@ -890,13 +892,15 @@ pub unsafe extern "C" fn system(command: *const c_char) -> c_int {
         exit(127);
 
         unreachable!();
-    } else {
+    } else if child_pid > 0 {
         let mut wstatus = 0;
         if Sys::waitpid(child_pid, &mut wstatus, 0) == !0 {
             return -1;
         }
 
         wstatus
+    } else {
+        -1
     }
 }
 

+ 1 - 1
src/header/time/mod.rs

@@ -157,7 +157,7 @@ pub extern "C" fn getdate(string: *const c_char) -> tm {
 
 #[no_mangle]
 pub unsafe extern "C" fn gmtime(timer: *const time_t) -> *mut tm {
-    unsafe { gmtime_r(timer, &mut TM) }
+    gmtime_r(timer, &mut TM)
 }
 
 const MONTH_DAYS: [[c_int; 12]; 2] = [

+ 1 - 1
src/header/unistd/mod.rs

@@ -148,7 +148,7 @@ pub unsafe extern "C" fn execve(
     argv: *const *mut c_char,
     envp: *const *mut c_char,
 ) -> c_int {
-    let path = unsafe { CStr::from_ptr(path) };
+    let path = CStr::from_ptr(path);
     Sys::execve(path, argv, envp)
 }
 

+ 1 - 0
src/macros.rs

@@ -1,6 +1,7 @@
 #[macro_export]
 macro_rules! c_str {
     ($lit:expr) => {
+        #[allow(unused_unsafe)]
         unsafe {
             $crate::c_str::CStr::from_ptr(concat!($lit, "\0").as_ptr()
                 as *const $crate::platform::types::c_char)

+ 8 - 16
src/platform/mod.rs

@@ -122,19 +122,15 @@ impl Write for StringWriter {
 }
 impl fmt::Write for StringWriter {
     fn write_str(&mut self, s: &str) -> fmt::Result {
-        unsafe {
-            // can't fail
-            self.write(s.as_bytes()).unwrap();
-        };
+        // can't fail
+        self.write(s.as_bytes()).unwrap();
         Ok(())
     }
 }
 impl WriteByte for StringWriter {
     fn write_u8(&mut self, byte: u8) -> fmt::Result {
-        unsafe {
-            // can't fail
-            self.write(&[byte]).unwrap();
-        }
+        // can't fail
+        self.write(&[byte]).unwrap();
         Ok(())
     }
 }
@@ -159,19 +155,15 @@ impl Write for UnsafeStringWriter {
 }
 impl fmt::Write for UnsafeStringWriter {
     fn write_str(&mut self, s: &str) -> fmt::Result {
-        unsafe {
-            // can't fail
-            self.write(s.as_bytes()).unwrap();
-        }
+        // can't fail
+        self.write(s.as_bytes()).unwrap();
         Ok(())
     }
 }
 impl WriteByte for UnsafeStringWriter {
     fn write_u8(&mut self, byte: u8) -> fmt::Result {
-        unsafe {
-            // can't fail
-            self.write(&[byte]).unwrap();
-        }
+        // can't fail
+        self.write(&[byte]).unwrap();
         Ok(())
     }
 }