2011-03-10 15:56:51 +01:00
|
|
|
native "rust" mod rustrt {
|
2011-06-10 12:56:42 -07:00
|
|
|
fn rust_list_files(str path) -> vec[str];
|
2011-05-12 17:24:54 +02:00
|
|
|
fn rust_dirent_filename(os::libc::dirent ent) -> str;
|
2011-03-10 15:56:51 +01:00
|
|
|
}
|
|
|
|
|
2011-04-19 13:35:49 -07:00
|
|
|
fn list_dir(str path) -> vec[str] {
|
2011-06-10 12:56:42 -07:00
|
|
|
ret rustrt::rust_list_files(path);
|
2011-03-10 15:56:51 +01:00
|
|
|
// TODO ensure this is always closed
|
2011-06-10 12:56:42 -07:00
|
|
|
|
|
|
|
// FIXME: No idea why, but this appears to corrupt memory on OSX. I suspect
|
|
|
|
// it has to do with the tasking primitives somehow, or perhaps the
|
|
|
|
// FFI. Worth investigating more when we're digging into the FFI and unsafe
|
|
|
|
// mode in more detail; in the meantime we just call list_files above and
|
|
|
|
// skip this code.
|
|
|
|
|
|
|
|
/*
|
2011-05-17 20:41:41 +02:00
|
|
|
auto dir = os::libc::opendir(str::buf(path));
|
2011-05-02 17:47:24 -07:00
|
|
|
assert (dir as uint != 0u);
|
2011-05-16 18:21:22 -07:00
|
|
|
let vec[str] result = [];
|
2011-03-10 15:56:51 +01:00
|
|
|
while (true) {
|
2011-06-10 12:56:42 -07:00
|
|
|
auto ent = os::libc::readdir(dir);
|
|
|
|
if (ent as int == 0) {
|
|
|
|
os::libc::closedir(dir);
|
|
|
|
ret result;
|
|
|
|
}
|
|
|
|
vec::push[str](result, rustrt::rust_dirent_filename(ent));
|
2011-03-10 15:56:51 +01:00
|
|
|
}
|
2011-05-12 17:24:54 +02:00
|
|
|
os::libc::closedir(dir);
|
2011-03-10 15:56:51 +01:00
|
|
|
ret result;
|
2011-06-10 12:56:42 -07:00
|
|
|
*/
|
2011-03-10 15:56:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const char path_sep = '/';
|
2011-05-05 14:31:10 -07:00
|
|
|
const char alt_path_sep = '/';
|
2011-03-16 14:58:02 -07:00
|
|
|
|
|
|
|
// Local Variables:
|
|
|
|
// mode: rust;
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
|
|
|
|
// End:
|