about summary refs log tree commit diff
path: root/src/rt
diff options
context:
space:
mode:
authorJeff Olson <olson.jeffery@gmail.com>2013-02-20 22:46:26 -0800
committerBrian Anderson <banderson@mozilla.com>2013-03-11 15:38:55 -0700
commita69a2acfba1c09d2ca47f454ecff7b571c324d57 (patch)
treed3b952b31d20c922ef23871a0c2d84d09c944910 /src/rt
parent53db6c7e2a11764a806e87c7268d31288fa9171d (diff)
downloadrust-a69a2acfba1c09d2ca47f454ecff7b571c324d57.tar.gz
rust-a69a2acfba1c09d2ca47f454ecff7b571c324d57.zip
rt/core: port os::list_dir to rust ref #4812
Diffstat (limited to 'src/rt')
-rw-r--r--src/rt/rust_builtin.cpp66
-rw-r--r--src/rt/rust_util.h32
-rw-r--r--src/rt/rustrt.def.in5
3 files changed, 33 insertions, 70 deletions
diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp
index 2c9c4a70681..a621d61cdf7 100644
--- a/src/rt/rust_builtin.cpp
+++ b/src/rt/rust_builtin.cpp
@@ -247,49 +247,43 @@ debug_get_stk_seg() {
     return task->stk;
 }
 
-extern "C" CDECL rust_vec_box*
-rust_list_files(rust_str *path) {
-    rust_task *task = rust_get_current_task();
-    array_list<rust_str*> strings;
+extern "C" CDECL char*
 #if defined(__WIN32__)
-    WIN32_FIND_DATA FindFileData;
-    HANDLE hFind = FindFirstFile((char*)path->body.data, &FindFileData);
-    if (hFind != INVALID_HANDLE_VALUE) {
-        do {
-            rust_str *str = make_str(task->kernel, FindFileData.cFileName,
-                                     strlen(FindFileData.cFileName),
-                                     "list_files_str");
-            strings.push(str);
-        } while (FindNextFile(hFind, &FindFileData));
-        FindClose(hFind);
-    }
+rust_list_dir_val(WIN32_FIND_DATA* entry_ptr) {
+    return entry_ptr->cFileName;
+}
 #else
-    DIR *dirp = opendir((char*)path->body.data);
-  if (dirp) {
-      struct dirent *dp;
-      while ((dp = readdir(dirp))) {
-          rust_vec_box *str = make_str(task->kernel, dp->d_name,
-                                       strlen(dp->d_name),
-                                       "list_files_str");
-          strings.push(str);
-      }
-      closedir(dirp);
-  }
+rust_list_dir_val(dirent* entry_ptr) {
+    return entry_ptr->d_name;
+}
 #endif
 
-  rust_vec_box *vec = (rust_vec_box *)
-      task->kernel->malloc(vec_size<rust_vec_box*>(strings.size()),
-                           "list_files_vec");
-  size_t alloc_sz = sizeof(rust_vec*) * strings.size();
-  vec->body.fill = vec->body.alloc = alloc_sz;
-  memcpy(&vec->body.data[0], strings.data(), alloc_sz);
-  return vec;
+extern "C" CDECL size_t
+#if defined(__WIN32__)
+rust_list_dir_wfd_size() {
+    return sizeof(WIN32_FIND_DATAW);
+}
+#else
+rust_list_dir_wfd_size() {
+    return 0;
 }
+#endif
 
-extern "C" CDECL rust_vec_box*
-rust_list_files2(rust_str **path) {
-    return rust_list_files(*path);
+extern "C" CDECL void*
+#if defined(__WIN32__)
+rust_list_dir_wfd_fp_buf(WIN32_FIND_DATAW* wfd) {
+    if(wfd == NULL) {
+        return 0;
+    }
+    else {
+        return wfd->cFileName;
+    }
 }
+#else
+rust_list_dir_wfd_fp_buf(void* wfd) {
+    return 0;
+}
+#endif
 
 extern "C" CDECL int
 rust_path_is_dir(char *path) {
diff --git a/src/rt/rust_util.h b/src/rt/rust_util.h
index fbedb9bc6ef..101d04c8804 100644
--- a/src/rt/rust_util.h
+++ b/src/rt/rust_util.h
@@ -79,38 +79,6 @@ inline void reserve_vec_exact(rust_vec_box** vpp,
 
 typedef rust_vec_box rust_str;
 
-inline rust_str *
-make_str(rust_kernel* kernel, const char* c, size_t strlen,
-         const char* name) {
-    size_t str_fill = strlen + 1;
-    size_t str_alloc = str_fill;
-    rust_str *str = (rust_str *)
-        kernel->malloc(vec_size<char>(str_fill), name);
-    str->header.td = &str_body_tydesc;
-    str->body.fill = str_fill;
-    str->body.alloc = str_alloc;
-    memcpy(&str->body.data, c, strlen);
-    str->body.data[strlen] = '\0';
-    return str;
-}
-
-inline rust_vec_box *
-make_str_vec(rust_kernel* kernel, size_t nstrs, char **strs) {
-    rust_vec_box *v = (rust_vec_box *)
-        kernel->malloc(vec_size<rust_vec_box*>(nstrs),
-                       "str vec interior");
-    // FIXME: should have a real td (Issue #2639)
-    v->header.td = NULL;
-    v->body.fill = v->body.alloc = sizeof(rust_vec_box*) * nstrs;
-    for (size_t i = 0; i < nstrs; ++i) {
-        rust_str *str = make_str(kernel, strs[i],
-                                 strlen(strs[i]),
-                                 "str");
-        ((rust_str**)&v->body.data)[i] = str;
-    }
-    return v;
-}
-
 inline size_t get_box_size(size_t body_size, size_t body_align) {
     size_t header_size = sizeof(rust_opaque_box);
     // FIXME (#2699): This alignment calculation is suspicious. Is it right?
diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in
index ddbd4729782..284f827bc75 100644
--- a/src/rt/rustrt.def.in
+++ b/src/rt/rustrt.def.in
@@ -32,8 +32,9 @@ rust_path_exists
 rust_get_stdin
 rust_get_stdout
 rust_get_stderr
-rust_list_files
-rust_list_files2
+rust_list_dir_val
+rust_list_dir_wfd_size
+rust_list_dir_wfd_fp_buf
 rust_log_console_on
 rust_log_console_off
 rust_process_wait