about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorCorey Richardson <corey@octayn.net>2014-02-26 12:58:41 -0500
committerAlex Crichton <alex@alexcrichton.com>2014-04-04 09:31:44 -0700
commit0459ee77d0c764cc27950465cb19053e1456cc95 (patch)
tree9fa60ca3a09b8bf87bcd9a53ca3c673f84610e5c /src/libstd
parent06ad5eb459f1072d79a815210d69af55ef174d20 (diff)
downloadrust-0459ee77d0c764cc27950465cb19053e1456cc95.tar.gz
rust-0459ee77d0c764cc27950465cb19053e1456cc95.zip
Fix fallout from std::libc separation
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/c_str.rs43
-rw-r--r--src/libstd/io/pipe.rs9
-rw-r--r--src/libstd/os.rs6
3 files changed, 34 insertions, 24 deletions
diff --git a/src/libstd/c_str.rs b/src/libstd/c_str.rs
index ca1a05a2647..6acf0eb0cee 100644
--- a/src/libstd/c_str.rs
+++ b/src/libstd/c_str.rs
@@ -39,25 +39,28 @@ unnecessary amounts of allocations.
 An example of creating and using a C string would be:
 
 ```rust
-use std::libc;
+extern crate libc;
+
 extern {
     fn puts(s: *libc::c_char);
 }
 
-let my_string = "Hello, world!";
-
-// Allocate the C string with an explicit local that owns the string. The
-// `c_buffer` pointer will be deallocated when `my_c_string` goes out of scope.
-let my_c_string = my_string.to_c_str();
-my_c_string.with_ref(|c_buffer| {
-    unsafe { puts(c_buffer); }
-});
-
-// Don't save off the allocation of the C string, the `c_buffer` will be
-// deallocated when this block returns!
-my_string.with_c_str(|c_buffer| {
-    unsafe { puts(c_buffer); }
-});
+fn main() {
+    let my_string = "Hello, world!";
+
+    // Allocate the C string with an explicit local that owns the string. The
+    // `c_buffer` pointer will be deallocated when `my_c_string` goes out of scope.
+    let my_c_string = my_string.to_c_str();
+    my_c_string.with_ref(|c_buffer| {
+        unsafe { puts(c_buffer); }
+    });
+
+    // Don't save off the allocation of the C string, the `c_buffer` will be
+    // deallocated when this block returns!
+    my_string.with_c_str(|c_buffer| {
+        unsafe { puts(c_buffer); }
+    });
+}
  ```
 
 */
@@ -266,11 +269,13 @@ pub trait ToCStr {
     /// # Example
     ///
     /// ```rust
-    /// use std::libc;
+    /// extern crate libc;
     ///
-    /// let s = "PATH".with_c_str(|path| unsafe {
-    ///     libc::getenv(path)
-    /// });
+    /// fn main() {
+    ///     let s = "PATH".with_c_str(|path| unsafe {
+    ///         libc::getenv(path)
+    ///     });
+    /// }
     /// ```
     ///
     /// # Failure
diff --git a/src/libstd/io/pipe.rs b/src/libstd/io/pipe.rs
index 75ec3d8614e..6eff453b60d 100644
--- a/src/libstd/io/pipe.rs
+++ b/src/libstd/io/pipe.rs
@@ -38,11 +38,14 @@ impl PipeStream {
     ///
     /// ```rust
     /// # #[allow(unused_must_use)];
-    /// use std::libc;
+    /// extern crate libc;
+    ///
     /// use std::io::pipe::PipeStream;
     ///
-    /// let mut pipe = PipeStream::open(libc::STDERR_FILENO);
-    /// pipe.write(bytes!("Hello, stderr!"));
+    /// fn main() {
+    ///     let mut pipe = PipeStream::open(libc::STDERR_FILENO);
+    ///     pipe.write(bytes!("Hello, stderr!"));
+    /// }
     /// ```
     pub fn open(fd: libc::c_int) -> IoResult<PipeStream> {
         LocalIo::maybe_raise(|io| {
diff --git a/src/libstd/os.rs b/src/libstd/os.rs
index a5583afb31d..a16113cb48f 100644
--- a/src/libstd/os.rs
+++ b/src/libstd/os.rs
@@ -932,8 +932,9 @@ pub fn page_size() -> uint {
 /// Returns the page size of the current architecture in bytes.
 #[cfg(windows)]
 pub fn page_size() -> uint {
+    use mem;
     unsafe {
-        let mut info = libc::SYSTEM_INFO::new();
+        let mut info = mem::uninit();
         libc::GetSystemInfo(&mut info);
 
         return info.dwPageSize as uint;
@@ -1250,8 +1251,9 @@ impl MemoryMap {
     /// Granularity of MapAddr() and MapOffset() parameter values.
     /// This may be greater than the value returned by page_size().
     pub fn granularity() -> uint {
+        use mem;
         unsafe {
-            let mut info = libc::SYSTEM_INFO::new();
+            let mut info = mem::uninit();
             libc::GetSystemInfo(&mut info);
 
             return info.dwAllocationGranularity as uint;