@@ -461,11 +461,12 @@ global state. In order to access these variables, you declare them in `extern`
461
461
blocks with the ` static ` keyword:
462
462
463
463
``` rust,no_run
464
- use std::os::raw::c_int;
464
+ # #![feature(libc)]
465
+ extern crate libc;
465
466
466
467
#[link(name = "readline")]
467
468
extern {
468
- static rl_readline_version: c_int;
469
+ static rl_readline_version: libc:: c_int;
469
470
}
470
471
471
472
fn main() {
@@ -479,14 +480,15 @@ interface. To do this, statics can be declared with `mut` so we can mutate
479
480
them.
480
481
481
482
``` rust,no_run
483
+ # #![feature(libc)]
484
+ extern crate libc;
482
485
483
486
use std::ffi::CString;
484
- use std::os::raw::c_char;
485
487
use std::ptr;
486
488
487
489
#[link(name = "readline")]
488
490
extern {
489
- static mut rl_prompt: *const c_char;
491
+ static mut rl_prompt: *const libc:: c_char;
490
492
}
491
493
492
494
fn main() {
@@ -511,13 +513,14 @@ calling foreign functions. Some foreign functions, most notably the Windows API,
511
513
conventions. Rust provides a way to tell the compiler which convention to use:
512
514
513
515
``` rust
514
- use std :: os :: raw :: c_int;
516
+ # #![feature(libc)]
517
+ extern crate libc;
515
518
516
519
#[cfg(all(target_os = " win32" , target_arch = " x86" ))]
517
520
#[link(name = " kernel32" )]
518
521
#[allow(non_snake_case)]
519
522
extern " stdcall" {
520
- fn SetEnvironmentVariableA (n : * const u8 , v : * const u8 ) -> c_int ;
523
+ fn SetEnvironmentVariableA (n : * const u8 , v : * const u8 ) -> libc :: c_int ;
521
524
}
522
525
# fn main () { }
523
526
```
@@ -690,11 +693,12 @@ void bar(void *arg);
690
693
We can represent this in Rust with the `c_void` type:
691
694
692
695
```rust
693
- use std::os::raw::c_void;
696
+ # #![feature(libc)]
697
+ extern crate libc;
694
698
695
699
extern "C" {
696
- pub fn foo(arg: *mut c_void);
697
- pub fn bar(arg: *mut c_void);
700
+ pub fn foo(arg: *mut libc:: c_void);
701
+ pub fn bar(arg: *mut libc:: c_void);
698
702
}
699
703
# fn main() {}
700
704
```
0 commit comments