about summary refs log tree commit diff
path: root/src/rt
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-04-15 23:21:13 -0700
committerAlex Crichton <alex@alexcrichton.com>2015-04-27 17:16:44 -0700
commit9348700007c6ac913df97c8e9e1ab7df6f91f130 (patch)
treea69d87dfe3b7e1e8c7cd9f7f48fdabdb1436c308 /src/rt
parentb772ce6342962792620e21623997d0d3b98164b7 (diff)
downloadrust-9348700007c6ac913df97c8e9e1ab7df6f91f130.tar.gz
rust-9348700007c6ac913df97c8e9e1ab7df6f91f130.zip
std: Expand the area of std::fs
This commit is an implementation of [RFC 1044][rfc] which adds additional
surface area to the `std::fs` module. All new APIs are `#[unstable]` behind
assorted feature names for each one.

[rfc]: https://github.com/rust-lang/rfcs/pull/1044

The new APIs added are:

* `fs::canonicalize` - bindings to `realpath` on unix and
  `GetFinalPathNameByHandle` on windows.
* `fs::symlink_metadata` - similar to `lstat` on unix
* `fs::FileType` and accessor methods as `is_{file,dir,symlink}`
* `fs::Metadata::file_type` - accessor for the raw file type
* `fs::DirEntry::metadata` - acquisition of metadata which is free on Windows
  but requires a syscall on unix.
* `fs::DirEntry::file_type` - access the file type which may not require a
  syscall on most platforms.
* `fs::DirEntry::file_name` - access just the file name without leading
  components.
* `fs::PathExt::symlink_metadata` - convenience method for the top-level
  function.
* `fs::PathExt::canonicalize` - convenience method for the top-level
  function.
* `fs::PathExt::read_link` - convenience method for the top-level
  function.
* `fs::PathExt::read_dir` - convenience method for the top-level
  function.
* `std::os::raw` - type definitions for raw OS/C types available on all
  platforms.
* `std::os::$platform` - new modules have been added for all currently supported
  platforms (e.g. those more specific than just `unix`).
* `std::os::$platform::raw` - platform-specific type definitions. These modules
  are populated with the bare essentials necessary for lowing I/O types into
  their raw representations, and currently largely consist of the `stat`
  definition for unix platforms.

This commit also deprecates `Metadata::{modified, accessed}` in favor of
inspecting the raw representations via the lowering methods of `Metadata`.
Diffstat (limited to 'src/rt')
-rw-r--r--src/rt/rust_builtin.c93
1 files changed, 23 insertions, 70 deletions
diff --git a/src/rt/rust_builtin.c b/src/rt/rust_builtin.c
index db1a602b404..362439c1469 100644
--- a/src/rt/rust_builtin.c
+++ b/src/rt/rust_builtin.c
@@ -15,12 +15,13 @@
 #include <stdlib.h>
 
 #if !defined(__WIN32__)
-#include <sys/time.h>
-#include <sys/types.h>
 #include <dirent.h>
+#include <pthread.h>
 #include <signal.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/types.h>
 #include <unistd.h>
-#include <pthread.h>
 #else
 #include <windows.h>
 #include <wincrypt.h>
@@ -41,44 +42,31 @@
 //include valgrind.h after stdint.h so that uintptr_t is defined for msys2 w64
 #include "valgrind/valgrind.h"
 
-#ifdef __APPLE__
-#if (TARGET_OS_IPHONE)
-extern char **environ;
-#endif
-#endif
-
-#if defined(__FreeBSD__) || defined(__linux__) || defined(__ANDROID__) || \
-    defined(__DragonFly__) || defined(__Bitrig__) || defined(__OpenBSD__)
-extern char **environ;
-#endif
-
-#if defined(__WIN32__)
-char**
-rust_env_pairs() {
-    return 0;
-}
-#else
-char**
-rust_env_pairs() {
-#if defined(__APPLE__) && !(TARGET_OS_IPHONE)
-    char **environ = *_NSGetEnviron();
-#endif
-    return environ;
-}
-#endif
-
+#ifndef _WIN32
 char*
-#if defined(__WIN32__)
-rust_list_dir_val(WIN32_FIND_DATA* entry_ptr) {
-    return entry_ptr->cFileName;
-}
-#else
 rust_list_dir_val(struct dirent* entry_ptr) {
     return entry_ptr->d_name;
 }
+
+int
+rust_dir_get_mode(struct dirent* entry_ptr) {
+#if defined(_DIRENT_HAVE_D_TYPE)
+    switch (entry_ptr->d_type) {
+        case DT_BLK: return S_IFBLK;
+        case DT_CHR: return S_IFCHR;
+        case DT_FIFO: return S_IFIFO;
+        case DT_LNK: return S_IFLNK;
+        case DT_REG: return S_IFREG;
+        case DT_SOCK: return S_IFSOCK;
+    }
 #endif
+    return -1;
+}
 
-#ifndef _WIN32
+ino_t
+rust_dir_get_ino(struct dirent* entry_ptr) {
+    return entry_ptr->d_ino;
+}
 
 DIR*
 rust_opendir(char *dirname) {
@@ -94,21 +82,6 @@ int
 rust_dirent_t_size() {
     return sizeof(struct dirent);
 }
-
-#else
-
-void
-rust_opendir() {
-}
-
-void
-rust_readdir() {
-}
-
-void
-rust_dirent_t_size() {
-}
-
 #endif
 
 uintptr_t
@@ -173,26 +146,6 @@ rust_valgrind_stack_deregister(unsigned int id) {
   VALGRIND_STACK_DEREGISTER(id);
 }
 
-#if defined(__WIN32__)
-
-void
-rust_unset_sigprocmask() {
-    // empty stub for windows to keep linker happy
-}
-
-#else
-
-void
-rust_unset_sigprocmask() {
-    // this can't be safely converted to rust code because the
-    // representation of sigset_t is platform-dependent
-    sigset_t sset;
-    sigemptyset(&sset);
-    sigprocmask(SIG_SETMASK, &sset, NULL);
-}
-
-#endif
-
 #if defined(__DragonFly__)
 #include <errno.h>
 // In DragonFly __error() is an inline function and as such