rust/src/libstd
bors 930f7790fb auto merge of #9497 : pnkfelix/rust/fsk-7752-use-fcnptr-for-glob-errfunc, r=cmr
Fix #7752.

~~(The glob API is a little funky; I tried to make a small test for it, which I'll add to the end of this description, and its not clear whether globfree is supposed to free solely the structure allocated by glob itself, or if it is going to try to free more than that.)~~ (The previous note was a user-error: I was misusing the CString API.)

Anyway, this seems to work in terms of calling errfunc where expected.)

```rust
#[allow(unused_imports)];
use std::libc::types::os::arch::c95::{c_char, c_int, size_t};
use std::libc::funcs::posix01::glob;
use std::libc::types::os::common::posix01::glob_t;
use std::libc::consts::os::posix01::{GLOB_APPEND, GLOB_DOOFFS, GLOB_ERR,
                                     GLOB_MARK, GLOB_NOCHECK, GLOB_NOSORT,
                                     GLOB_NOESCAPE, GLOB_NOSPACE,
                                     GLOB_ABORTED, GLOB_NOMATCH};
use std::ptr;
use std::c_str;

#[fixed_stack_segment]
fn main() {
    let mut g = glob_t {
        gl_pathc:  0, // size_t,
        __unused1: 0, // c_int,
        gl_offs:   2, // size_t,
        __unused2: 0, // c_int,
        gl_pathv:  ptr::null(), // **c_char,

        __unused3: ptr::null(), // *c_void,

        __unused4: ptr::null(), // *c_void,
        __unused5: ptr::null(), // *c_void,
        __unused6: ptr::null(), // *c_void,
        __unused7: ptr::null(), // *c_void,
        __unused8: ptr::null(), // *c_void,
    };

    extern "C" fn errfunc(_epath: *c_char, _errno: int) -> int {
        println!("errfunc called");
        return 0;
    }

    struct Reduced { pathc: size_t, offs: size_t, pathv: **c_char, }
    impl Reduced {
        fn from(g: &glob_t) -> Reduced {
            Reduced {pathc: g.gl_pathc, offs: g.gl_offs, pathv: g.gl_pathv}
        }
    }

    do ("*.rs/*").with_c_str |pat| {
        println!("calling glob");
        unsafe { glob::glob(pat, GLOB_DOOFFS, errfunc, &mut g); }
        println!("After glob call");

        println!("g: {:?}", Reduced::from(&g));
        for i in range(0, g.gl_pathc as int) {
            unsafe {
                let p : **c_char = ptr::offset(g.gl_pathv, g.gl_offs as int + i);
                let x = c_str::CString::new(*p, false);
                match x.as_str() {
                    Some(s) => {
                        println!("gl_pathc[{:d}]: {:?}", i, s);
                    }
                    None => {
                        println!("gl_pathc[{:d}]: unvalid", i);
                    }
                }
            }
        }
    }

    println!("calling globfree on g: {:?}", g);
    unsafe { glob::globfree(&mut g); }
    println!("after globfree call");

}

```
2013-09-26 04:16:03 -07:00
..
fmt rustdoc: Change all code-blocks with a script 2013-09-25 14:27:42 -07:00
num rustdoc: Change all code-blocks with a script 2013-09-25 14:27:42 -07:00
rand rustdoc: Change all code-blocks with a script 2013-09-25 14:27:42 -07:00
rt auto merge of #9490 : alexcrichton/rust/issue-9487, r=cmr 2013-09-26 00:30:57 -07:00
str Some work on std::ascii: Marked unsafe function unsafe, added moving implementations 2013-09-09 15:07:22 +02:00
task rustdoc: Change all code-blocks with a script 2013-09-25 14:27:42 -07:00
unstable rustdoc: Change all code-blocks with a script 2013-09-25 14:27:42 -07:00
at_vec.rs std::at_vec: Fix segfault on overflow when resizing ~[@T] 2013-09-17 02:48:00 +02:00
bool.rs rustdoc: Change all code-blocks with a script 2013-09-25 14:27:42 -07:00
borrow.rs std::borrow: Use raw pointer comparison for ref_eq 2013-09-18 06:05:06 +02:00
c_str.rs rustdoc: Change all code-blocks with a script 2013-09-25 14:27:42 -07:00
cast.rs rustdoc: Change all code-blocks with a script 2013-09-25 14:27:42 -07:00
cell.rs librustc: Ensure that type parameters are in the right positions in paths. 2013-08-27 18:47:57 -07:00
char.rs Added is_control function, method, and tests. 2013-09-23 17:10:48 -04:00
cleanup.rs librustc: Remove &const and *const from the language. 2013-08-27 18:46:51 -07:00
clone.rs std: Implement Clone and DeepClone for extern "Rust" fn 2013-07-29 19:43:21 +02:00
cmp.rs Now inline default 'ne' methods 2013-08-30 22:02:24 -04:00
comm.rs Add SharedPort wrapper around rt::comm::SharedPort 2013-09-14 22:50:28 +02:00
condition.rs rustdoc: Change all code-blocks with a script 2013-09-25 14:27:42 -07:00
container.rs container: inline contains_key default method 2013-08-20 22:05:03 -04:00
default.rs std: Add a bunch of Default impls 2013-09-12 18:54:13 -07:00
either.rs std: Add ToEither/IntoEither/AsEither 2013-09-12 18:54:12 -07:00
from_str.rs Add from_str docs 2013-09-05 00:58:12 -04:00
hash.rs rename std::iterator to std::iter 2013-09-09 03:21:46 -04:00
hashmap.rs std: merge rand::{Rng,RngUtil} with default methods. 2013-09-23 00:11:42 +10:00
io.rs rustdoc: Change all code-blocks with a script 2013-09-25 14:27:42 -07:00
iter.rs rustdoc: Change all code-blocks with a script 2013-09-25 14:27:42 -07:00
kinds.rs kinds: update documentation 2013-08-15 21:12:34 -04:00
libc.rs errfunc ptr is nullable, so use Option as part of interface to glob (#7752). 2013-09-25 23:38:59 +02:00
local_data.rs rustdoc: Change all code-blocks with a script 2013-09-25 14:27:42 -07:00
logging.rs Register new snapshots 2013-09-18 11:07:22 -07:00
macros.rs Implement a web backend for rustdoc_ng 2013-09-20 22:49:03 -07:00
managed.rs std: implement Total{Ord,Eq} for pointers. 2013-08-04 19:46:52 +10:00
ops.rs switch Drop to &mut self 2013-09-16 22:19:23 -04:00
option.rs rustdoc: Change all code-blocks with a script 2013-09-25 14:27:42 -07:00
os.rs std: merge rand::{Rng,RngUtil} with default methods. 2013-09-23 00:11:42 +10:00
owned.rs std: implement Total{Ord,Eq} for pointers. 2013-08-04 19:46:52 +10:00
path.rs rustpkg: Search for packages correctly when using the rust_path_hack 2013-09-25 11:12:24 -07:00
prelude.rs std: Replace CloneableTuple with Tuple, which takes self by-val. 2013-09-25 19:00:08 +10:00
ptr.rs Register new snapshots 2013-09-18 11:07:22 -07:00
reflect.rs librustc: Remove @fn managed closures from the language. 2013-09-23 18:23:21 -07:00
repr.rs auto merge of #9065 : thestinger/rust/iter, r=alexcrichton 2013-09-09 00:26:07 -07:00
result.rs std::result: Remove function map_opt 2013-09-22 13:09:18 +02:00
routine.rs libsyntax: Introduce routines and remove all @fns from libsyntax save the old visitor 2013-09-23 18:23:21 -07:00
run.rs auto merge of #9280 : alexcrichton/rust/less-c++, r=brson 2013-09-18 22:15:59 -07:00
select.rs auto merge of #9062 : blake2-ppc/rust/vec-iterator, r=alexcrichton 2013-09-09 21:31:03 -07:00
send_str.rs Corrected a few small style issues 2013-09-16 17:45:24 +02:00
std.rs rustdoc: Strip hidden docs by default. 2013-09-25 14:27:43 -07:00
str.rs Moved StrSlice doc comments from impl to trait. 2013-09-26 04:44:36 +02:00
sys.rs Register new snapshots 2013-09-18 11:07:22 -07:00
to_bytes.rs std: fix a warning 2013-09-12 18:54:12 -07:00
to_str.rs rename std::iterator to std::iter 2013-09-09 03:21:46 -04:00
trie.rs Use std::iter::range_step 2013-09-15 00:41:34 -04:00
tuple.rs std: Replace CloneableTuple with Tuple, which takes self by-val. 2013-09-25 19:00:08 +10:00
unicode.rs rename std::iterator to std::iter 2013-09-09 03:21:46 -04:00
unit.rs std: Add a bunch of Default impls 2013-09-12 18:54:13 -07:00
util.rs auto merge of #9354 : thestinger/rust/cleanup, r=alexcrichton 2013-09-21 01:35:59 -07:00
vec.rs rustdoc: Change all code-blocks with a script 2013-09-25 14:27:42 -07:00