Browse Source

Merge branch 'pal' into 'master'

Intense refactor

See merge request redox-os/relibc!159
Jeremy Soller 6 years ago
parent
commit
70eda382d3
100 changed files with 1655 additions and 1105 deletions
  1. 61 437
      Cargo.lock
  2. 16 39
      Cargo.toml
  3. 14 5
      Makefile
  4. 1 0
      build.rs
  5. 1 7
      fmt.sh
  6. 20 0
      include.sh
  7. 0 14
      src/arpainet/Cargo.toml
  8. 0 11
      src/arpainet/build.rs
  9. 1255 0
      src/c_str.rs
  10. 1 2
      src/crt0/Cargo.toml
  11. 8 100
      src/crt0/src/lib.rs
  12. 0 11
      src/ctype/Cargo.toml
  13. 0 11
      src/ctype/build.rs
  14. 0 15
      src/dirent/Cargo.toml
  15. 0 11
      src/dirent/build.rs
  16. 0 11
      src/errno/Cargo.toml
  17. 0 11
      src/errno/build.rs
  18. 0 11
      src/fcntl/Cargo.toml
  19. 0 11
      src/fcntl/build.rs
  20. 0 13
      src/fcntl/src/linux.rs
  21. 0 10
      src/fenv/Cargo.toml
  22. 0 11
      src/fenv/build.rs
  23. 0 11
      src/float/Cargo.toml
  24. 0 11
      src/float/build.rs
  25. 0 10
      src/fnmatch/Cargo.toml
  26. 0 11
      src/fnmatch/build.rs
  27. 0 11
      src/grp/Cargo.toml
  28. 0 11
      src/grp/build.rs
  29. 0 0
      src/header/_oldlib/dns/answer.rs
  30. 0 0
      src/header/_oldlib/dns/mod.rs
  31. 0 0
      src/header/_oldlib/dns/query.rs
  32. 0 0
      src/header/_oldlib/event.rs
  33. 0 0
      src/header/_oldlib/file.rs
  34. 0 0
      src/header/_oldlib/folder.rs
  35. 0 0
      src/header/_oldlib/hostname.rs
  36. 0 0
      src/header/_oldlib/lib.rs
  37. 0 0
      src/header/_oldlib/macros.rs
  38. 0 0
      src/header/_oldlib/mallocnull.rs
  39. 0 0
      src/header/_oldlib/netdb.rs
  40. 0 0
      src/header/_oldlib/process.rs
  41. 0 0
      src/header/_oldlib/rawfile.rs
  42. 0 0
      src/header/_oldlib/redox.rs
  43. 0 0
      src/header/_oldlib/socket.rs
  44. 0 0
      src/header/_oldlib/termios.rs
  45. 0 0
      src/header/_oldlib/time.rs
  46. 0 0
      src/header/_oldlib/types.rs
  47. 0 0
      src/header/_oldlib/unimpl.rs
  48. 0 0
      src/header/_oldlib/user.rs
  49. 7 0
      src/header/_pthread/cbindgen.toml
  50. 119 147
      src/header/_pthread/mod.rs
  51. 0 0
      src/header/_template/cbindgen.toml
  52. 0 4
      src/header/_template/mod.rs
  53. 7 0
      src/header/aio/cbindgen.toml
  54. 17 14
      src/header/aio/mod.rs
  55. 1 1
      src/header/arpa_inet/cbindgen.toml
  56. 14 23
      src/header/arpa_inet/mod.rs
  57. 0 0
      src/header/ctype/cbindgen.toml
  58. 0 4
      src/header/ctype/mod.rs
  59. 0 0
      src/header/dirent/cbindgen.toml
  60. 9 13
      src/header/dirent/mod.rs
  61. 0 0
      src/header/errno/cbindgen.toml
  62. 1 4
      src/header/errno/mod.rs
  63. 0 0
      src/header/fcntl/cbindgen.toml
  64. 15 0
      src/header/fcntl/linux.rs
  65. 6 14
      src/header/fcntl/mod.rs
  66. 1 1
      src/header/fcntl/redox.rs
  67. 0 0
      src/header/fenv/cbindgen.toml
  68. 0 4
      src/header/fenv/mod.rs
  69. 0 0
      src/header/float/cbindgen.toml
  70. 1 6
      src/header/float/mod.rs
  71. 0 0
      src/header/fnmatch/cbindgen.toml
  72. 22 20
      src/header/fnmatch/mod.rs
  73. 0 0
      src/header/grp/cbindgen.toml
  74. 0 4
      src/header/grp/mod.rs
  75. 0 0
      src/header/inttypes/cbindgen.toml
  76. 4 11
      src/header/inttypes/mod.rs
  77. 0 0
      src/header/locale/cbindgen.toml
  78. 1 5
      src/header/locale/mod.rs
  79. 41 0
      src/header/mod.rs
  80. 0 0
      src/header/netinet_in/Cargo.toml
  81. 0 0
      src/header/netinet_in/cbindgen.toml
  82. 5 10
      src/header/netinet_in/mod.rs
  83. 0 0
      src/header/pwd/cbindgen.toml
  84. 7 10
      src/header/pwd/mod.rs
  85. 0 0
      src/header/semaphore/cbindgen.toml
  86. 0 4
      src/header/semaphore/mod.rs
  87. 0 0
      src/header/setjmp/impl/README.md
  88. 0 0
      src/header/setjmp/impl/aarch64/longjmp.s
  89. 0 0
      src/header/setjmp/impl/aarch64/setjmp.s
  90. 0 0
      src/header/setjmp/impl/arm/longjmp.s
  91. 0 0
      src/header/setjmp/impl/arm/setjmp.s
  92. 0 0
      src/header/setjmp/impl/i386/longjmp.s
  93. 0 0
      src/header/setjmp/impl/i386/setjmp.s
  94. 0 0
      src/header/setjmp/impl/m68k/longjmp.s
  95. 0 0
      src/header/setjmp/impl/m68k/setjmp.s
  96. 0 0
      src/header/setjmp/impl/microblaze/longjmp.s
  97. 0 0
      src/header/setjmp/impl/microblaze/setjmp.s
  98. 0 0
      src/header/setjmp/impl/mips/longjmp.S
  99. 0 0
      src/header/setjmp/impl/mips/setjmp.S
  100. 0 0
      src/header/setjmp/impl/mips64/longjmp.S

+ 61 - 437
Cargo.lock

@@ -6,30 +6,19 @@ dependencies = [
  "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
-[[package]]
-name = "arpainet"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "errno 0.1.0",
- "netinet 0.1.0",
- "platform 0.1.0",
- "sys_socket 0.1.0",
-]
-
 [[package]]
 name = "atty"
-version = "0.2.10"
+version = "0.2.11"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
  "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "bitflags"
-version = "1.0.3"
+version = "1.0.4"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
@@ -38,9 +27,9 @@ version = "0.5.2"
 dependencies = [
  "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
- "serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde 1.0.75 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde_derive 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)",
- "serde_json 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_json 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)",
  "standalone-syn 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
  "toml 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -48,12 +37,12 @@ dependencies = [
 
 [[package]]
 name = "cc"
-version = "1.0.18"
+version = "1.0.22"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
 name = "cfg-if"
-version = "0.1.4"
+version = "0.1.5"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
@@ -62,8 +51,8 @@ version = "2.32.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "atty 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
- "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
+ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
  "strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -73,80 +62,13 @@ dependencies = [
 [[package]]
 name = "compiler_builtins"
 version = "0.1.0"
-source = "git+https://github.com/rust-lang-nursery/compiler-builtins.git#5d370bb352c915225981d89b80227afa4836cb93"
+source = "git+https://github.com/rust-lang-nursery/compiler-builtins.git#3caed3c80207fa43ba2963949c5f104a63c4264e"
 
 [[package]]
 name = "crt0"
 version = "0.1.0"
 dependencies = [
- "platform 0.1.0",
- "stdio 0.1.0",
-]
-
-[[package]]
-name = "ctype"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "platform 0.1.0",
-]
-
-[[package]]
-name = "dirent"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "errno 0.1.0",
- "fcntl 0.1.0",
- "platform 0.1.0",
- "stdio 0.1.0",
- "unistd 0.1.0",
-]
-
-[[package]]
-name = "dtoa"
-version = "0.4.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-
-[[package]]
-name = "errno"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "platform 0.1.0",
-]
-
-[[package]]
-name = "fcntl"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "platform 0.1.0",
-]
-
-[[package]]
-name = "fenv"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "platform 0.1.0",
-]
-
-[[package]]
-name = "float"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "fenv 0.1.0",
- "platform 0.1.0",
-]
-
-[[package]]
-name = "fnmatch"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "platform 0.1.0",
+ "relibc 0.1.0",
 ]
 
 [[package]]
@@ -154,7 +76,7 @@ name = "fuchsia-zircon"
 version = "0.3.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
  "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
@@ -163,34 +85,6 @@ name = "fuchsia-zircon-sys"
 version = "0.3.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
-[[package]]
-name = "grp"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "platform 0.1.0",
-]
-
-[[package]]
-name = "in_h"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "platform 0.1.0",
- "sys_socket 0.1.0",
-]
-
-[[package]]
-name = "inttypes"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "ctype 0.1.0",
- "errno 0.1.0",
- "platform 0.1.0",
- "stdlib 0.1.0",
-]
-
 [[package]]
 name = "itoa"
 version = "0.4.2"
@@ -198,56 +92,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
 name = "lazy_static"
-version = "1.0.2"
+version = "1.1.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "spin 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "spin 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
+ "version_check 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "libc"
-version = "0.2.42"
+version = "0.2.43"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
-[[package]]
-name = "locale"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "platform 0.1.0",
-]
-
 [[package]]
 name = "log"
 version = "0.3.9"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "log 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "log"
-version = "0.4.3"
+version = "0.4.4"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
-name = "netinet"
-version = "0.1.0"
-dependencies = [
- "in_h 0.1.0",
-]
-
-[[package]]
-name = "platform"
-version = "0.1.0"
-dependencies = [
- "ralloc 1.0.0",
- "redox_syscall 0.1.40 (git+https://gitlab.redox-os.org/redox-os/syscall.git?branch=relibc)",
- "sc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "spin 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -258,16 +128,6 @@ dependencies = [
  "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
-[[package]]
-name = "pwd"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "errno 0.1.0",
- "fcntl 0.1.0",
- "platform 0.1.0",
-]
-
 [[package]]
 name = "quote"
 version = "0.3.15"
@@ -291,17 +151,17 @@ dependencies = [
 
 [[package]]
 name = "rand"
-version = "0.4.2"
+version = "0.4.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
  "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "rand"
-version = "0.5.4"
+version = "0.5.5"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -334,46 +194,15 @@ dependencies = [
 name = "relibc"
 version = "0.1.0"
 dependencies = [
- "arpainet 0.1.0",
- "cc 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cc 1.0.22 (registry+https://github.com/rust-lang/crates.io-index)",
  "compiler_builtins 0.1.0 (git+https://github.com/rust-lang-nursery/compiler-builtins.git)",
- "ctype 0.1.0",
- "dirent 0.1.0",
- "errno 0.1.0",
- "fcntl 0.1.0",
- "fenv 0.1.0",
- "float 0.1.0",
- "fnmatch 0.1.0",
- "grp 0.1.0",
- "inttypes 0.1.0",
- "locale 0.1.0",
- "netinet 0.1.0",
- "platform 0.1.0",
- "pwd 0.1.0",
- "semaphore 0.1.0",
- "setjmp 0.1.0",
- "signal 0.1.0",
- "stdio 0.1.0",
- "stdlib 0.1.0",
- "string 0.1.0",
- "strings 0.1.0",
- "sys_ioctl 0.1.0",
- "sys_mman 0.1.0",
- "sys_resource 0.1.0",
- "sys_select 0.1.0",
- "sys_socket 0.1.0",
- "sys_stat 0.1.0",
- "sys_time 0.1.0",
- "sys_times 0.1.0",
- "sys_un 0.1.0",
- "sys_utsname 0.1.0",
- "sys_wait 0.1.0",
- "termios 0.1.0",
- "time 0.1.0",
- "unistd 0.1.0",
- "utime 0.1.0",
- "wchar 0.1.0",
- "wctype 0.1.0",
+ "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "ralloc 1.0.0",
+ "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "redox_syscall 0.1.40 (git+https://gitlab.redox-os.org/redox-os/syscall.git?branch=relibc)",
+ "sc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "spin 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
+ "va_list 0.1.0",
 ]
 
 [[package]]
@@ -385,21 +214,18 @@ dependencies = [
 ]
 
 [[package]]
-name = "sc"
-version = "0.2.2"
+name = "ryu"
+version = "0.2.6"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
-name = "semaphore"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "platform 0.1.0",
-]
+name = "sc"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
 name = "serde"
-version = "1.0.70"
+version = "1.0.75"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "serde_derive 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -426,30 +252,17 @@ dependencies = [
 
 [[package]]
 name = "serde_json"
-version = "1.0.24"
+version = "1.0.26"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "dtoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "itoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
-name = "setjmp"
-version = "0.1.0"
-
-[[package]]
-name = "signal"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "errno 0.1.0",
- "platform 0.1.0",
+ "ryu 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde 1.0.75 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "spin"
-version = "0.4.8"
+version = "0.4.9"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
@@ -470,53 +283,6 @@ dependencies = [
  "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
-[[package]]
-name = "stdio"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "errno 0.1.0",
- "fcntl 0.1.0",
- "lazy_static 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "platform 0.1.0",
- "string 0.1.0",
- "va_list 0.1.0",
-]
-
-[[package]]
-name = "stdlib"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "ctype 0.1.0",
- "errno 0.1.0",
- "fcntl 0.1.0",
- "platform 0.1.0",
- "rand 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)",
- "string 0.1.0",
- "time 0.1.0",
- "unistd 0.1.0",
- "wchar 0.1.0",
-]
-
-[[package]]
-name = "string"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "errno 0.1.0",
- "platform 0.1.0",
- "signal 0.1.0",
-]
-
-[[package]]
-name = "strings"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "platform 0.1.0",
-]
-
 [[package]]
 name = "strsim"
 version = "0.7.0"
@@ -540,103 +306,12 @@ dependencies = [
  "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
-[[package]]
-name = "sys_ioctl"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "platform 0.1.0",
-]
-
-[[package]]
-name = "sys_mman"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "platform 0.1.0",
-]
-
-[[package]]
-name = "sys_resource"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "platform 0.1.0",
- "sys_time 0.1.0",
-]
-
-[[package]]
-name = "sys_select"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "platform 0.1.0",
-]
-
-[[package]]
-name = "sys_socket"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "platform 0.1.0",
-]
-
-[[package]]
-name = "sys_stat"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "platform 0.1.0",
-]
-
-[[package]]
-name = "sys_time"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "platform 0.1.0",
-]
-
-[[package]]
-name = "sys_times"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "platform 0.1.0",
-]
-
-[[package]]
-name = "sys_un"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "platform 0.1.0",
- "sys_socket 0.1.0",
-]
-
-[[package]]
-name = "sys_utsname"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "platform 0.1.0",
-]
-
-[[package]]
-name = "sys_wait"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "platform 0.1.0",
- "sys_resource 0.1.0",
-]
-
 [[package]]
 name = "tempdir"
 version = "0.3.7"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
@@ -645,19 +320,11 @@ name = "termion"
 version = "1.5.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
  "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
  "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
-[[package]]
-name = "termios"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "platform 0.1.0",
-]
-
 [[package]]
 name = "textwrap"
 version = "0.10.0"
@@ -666,21 +333,12 @@ dependencies = [
  "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
-[[package]]
-name = "time"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "errno 0.1.0",
- "platform 0.1.0",
-]
-
 [[package]]
 name = "toml"
 version = "0.4.6"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde 1.0.75 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -703,26 +361,6 @@ name = "unicode-xid"
 version = "0.1.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
-[[package]]
-name = "unistd"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "errno 0.1.0",
- "platform 0.1.0",
- "stdio 0.1.0",
- "string 0.1.0",
- "sys_time 0.1.0",
-]
-
-[[package]]
-name = "utime"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "platform 0.1.0",
-]
-
 [[package]]
 name = "va_list"
 version = "0.1.0"
@@ -734,7 +372,7 @@ dependencies = [
 name = "va_list-helper"
 version = "0.0.2"
 dependencies = [
- "cc 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cc 1.0.22 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -743,24 +381,9 @@ version = "0.8.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
-name = "wchar"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "errno 0.1.0",
- "platform 0.1.0",
- "stdio 0.1.0",
- "time 0.1.0",
- "va_list 0.1.0",
-]
-
-[[package]]
-name = "wctype"
-version = "0.1.0"
-dependencies = [
- "cbindgen 0.5.2",
- "platform 0.1.0",
-]
+name = "version_check"
+version = "0.1.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
 name = "winapi"
@@ -783,35 +406,35 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [metadata]
 "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
-"checksum atty 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "2fc4a1aa4c24c0718a250f0681885c1af91419d242f29eb8f2ab28502d80dbd1"
-"checksum bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c54bb8f454c567f21197eefcdbf5679d0bd99f2ddbe52e84c77061952e6789"
-"checksum cc 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)" = "2119ea4867bd2b8ed3aecab467709720b2d55b1bcfe09f772fd68066eaf15275"
-"checksum cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "efe5c877e17a9c717a0bf3613b2709f723202c4e4675cc8f12926ded29bcb17e"
+"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652"
+"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
+"checksum cc 1.0.22 (registry+https://github.com/rust-lang/crates.io-index)" = "4a6007c146fdd28d4512a794b07ffe9d8e89e6bf86e2e0c4ddff2e1fb54a0007"
+"checksum cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4e7bb64a8ebb0d856483e1e682ea3422f883c5f5615a90d51a2c82fe87fdd3"
 "checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e"
 "checksum compiler_builtins 0.1.0 (git+https://github.com/rust-lang-nursery/compiler-builtins.git)" = "<none>"
-"checksum dtoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6d301140eb411af13d3115f9a562c85cc6b541ade9dfa314132244aaee7489dd"
 "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
 "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
 "checksum itoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5adb58558dcd1d786b5f0bd15f3226ee23486e24b7b58304b60f64dc68e62606"
-"checksum lazy_static 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "fb497c35d362b6a331cfd94956a07fc2c78a4604cdbee844a81170386b996dd3"
-"checksum libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "b685088df2b950fccadf07a7187c8ef846a959c142338a48f9dc0b94517eb5f1"
+"checksum lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca488b89a5657b0a2ecd45b95609b3e848cf1755da332a0da46e2b2b1cb371a7"
+"checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d"
 "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b"
-"checksum log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "61bd98ae7f7b754bc53dca7d44b604f733c6bba044ea6f41bc8d89272d8161d2"
+"checksum log 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "cba860f648db8e6f269df990180c2217f333472b4a6e901e97446858487971e2"
 "checksum proc-macro2 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cd07deb3c6d1d9ff827999c7f9b04cdfd66b1b17ae508e14fe47b620f2282ae0"
 "checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
-"checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5"
-"checksum rand 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "12397506224b2f93e6664ffc4f664b29be8208e5157d3d90b44f09b5fae470ea"
+"checksum rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8356f47b32624fef5b3301c1be97e5944ecdd595409cc5da11d05f211db6cfbd"
+"checksum rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e464cd887e869cddcae8792a4ee31d23c7edd516700695608f5b98c67ee0131c"
 "checksum rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "edecf0f94da5551fc9b492093e30b041a891657db7940ee221f9d2f66e82eef2"
 "checksum redox_syscall 0.1.40 (git+https://gitlab.redox-os.org/redox-os/syscall.git?branch=relibc)" = "<none>"
 "checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1"
 "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
 "checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5"
+"checksum ryu 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7153dd96dade874ab973e098cb62fcdbb89a03682e46b144fd09550998d4a4a7"
 "checksum sc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4ebbb026ba4a707c25caec2db5ef59ad8b41f7ad77cad06257e06229c891f376"
-"checksum serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)" = "0c3adf19c07af6d186d91dae8927b83b0553d07ca56cbf7f2f32560455c91920"
+"checksum serde 1.0.75 (registry+https://github.com/rust-lang/crates.io-index)" = "22d340507cea0b7e6632900a176101fea959c7065d93ba555072da90aaaafc87"
 "checksum serde_derive 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)" = "652bc323d694dc925829725ec6c890156d8e70ae5202919869cb00fe2eff3788"
 "checksum serde_derive_internals 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)" = "32f1926285523b2db55df263d2aa4eb69ddcfa7a7eade6430323637866b513ab"
-"checksum serde_json 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)" = "c3c6908c7b925cd6c590358a4034de93dbddb20c45e1d021931459fd419bf0e2"
-"checksum spin 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14db77c5b914df6d6173dda9a3b3f5937bd802934fa5edaf934df06a3491e56f"
+"checksum serde_json 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)" = "44dd2cfde475037451fa99b7e5df77aa3cfd1536575fa8e7a538ab36dcde49ae"
+"checksum spin 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)" = "37b5646825922b96b5d7d676b5bb3458a54498e96ed7b0ce09dc43a07038fea4"
 "checksum standalone-quote 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dcedac1d6d98e7e9d1d6e628f5635af9566688ae5f6cea70a3976f495ae8d839"
 "checksum standalone-syn 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "115808f5187c07c23cb93eee49d542fae54c6e8285d3a24c6ff683fcde9243db"
 "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550"
@@ -826,6 +449,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 "checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
 "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
 "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a"
+"checksum version_check 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7716c242968ee87e5542f8021178248f267f295a5c4803beae8b8b7fd9bc6051"
 "checksum winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "773ef9dcc5f24b7d850d0ff101e542ff24c3b090a9768e03ff889fdef41f00fd"
 "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
 "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

+ 16 - 39
Cargo.toml

@@ -8,56 +8,33 @@ name = "c"
 crate-type = ["staticlib"]
 
 [workspace]
-members = ["src/crt0"]
+members = ["src/crt0", "cbindgen"]
 
 [build-dependencies]
 cc = "1.0.17"
 
 [dependencies]
-arpainet = { path = "src/arpainet" }
-ctype = { path = "src/ctype" }
-dirent = { path = "src/dirent" }
-errno = { path = "src/errno" }
-fcntl = { path = "src/fcntl" }
-fenv = { path = "src/fenv" }
-float = { path = "src/float" }
-fnmatch = { path = "src/fnmatch" }
-grp = { path = "src/grp" }
-inttypes = { path = "src/inttypes" }
-locale = { path = "src/locale" }
-netinet = { path = "src/netinet" }
-platform = { path = "src/platform" }
-pwd = { path = "src/pwd" }
-semaphore = { path = "src/semaphore" }
-setjmp = { path = "src/setjmp" }
-signal = { path = "src/signal" }
-stdio = { path = "src/stdio" }
-stdlib = { path = "src/stdlib" }
-string = { path = "src/string" }
-strings = { path = "src/strings" }
-sys_ioctl = { path = "src/sys_ioctl" }
-sys_mman = { path = "src/sys_mman" }
-sys_resource = { path = "src/sys_resource" }
-sys_select = { path = "src/sys_select" }
-sys_socket = { path = "src/sys_socket" }
-sys_stat = { path = "src/sys_stat" }
-sys_time = { path = "src/sys_time" }
-sys_times = { path = "src/sys_times" }
-sys_un = { path = "src/sys_un" }
-sys_utsname = { path = "src/sys_utsname" }
-sys_wait = { path = "src/sys_wait" }
-termios = { path = "src/termios" }
-time = { path = "src/time" }
-unistd = { path = "src/unistd" }
-utime = { path = "src/utime" }
-wchar = { path = "src/wchar" }
-wctype = { path = "src/wctype" }
+lazy_static = { version = "*", features = ["nightly", "spin_no_std"] }
+rand = { version = "0.5.2", default-features = false }
+va_list = { path = "va_list", features = ["no_std"] }
 
 [dependencies.compiler_builtins]
 git = "https://github.com/rust-lang-nursery/compiler-builtins.git"
 default-features = false
 features = ["no-lang-items", "mangled-names"]
 
+[dependencies.ralloc]
+path = "ralloc"
+default-features = false
+optional = true
+
+[target.'cfg(target_os = "linux")'.dependencies]
+sc = "0.2"
+
+[target.'cfg(target_os = "redox")'.dependencies]
+redox_syscall = { git = "https://gitlab.redox-os.org/redox-os/syscall.git", branch = "relibc" }
+spin = "0.4"
+
 [profile.dev]
 panic = "abort"
 

+ 14 - 5
Makefile

@@ -20,7 +20,7 @@ SRC=\
 	src/*/*/* \
 	src/*/*/*/*
 
-.PHONY: all clean fmt install libc libm test
+.PHONY: all clean fmt include install libc libm test
 
 all: | libc libm
 
@@ -28,6 +28,9 @@ clean:
 	cargo clean
 	make -C tests clean
 
+check:
+	cargo check
+
 fmt:
 	./fmt.sh
 
@@ -35,14 +38,14 @@ install: all
 	mkdir -pv "$(DESTDIR)/lib"
 	mkdir -pv "$(DESTDIR)/include"
 	cp -rv "include"/* "$(DESTDIR)/include"
-	cp -rv "target/include"/* "$(DESTDIR)/include"
+	cp -rv "$(BUILD)/include"/* "$(DESTDIR)/include"
 	cp -v "$(BUILD)/release/libc.a" "$(DESTDIR)/lib"
 	cp -v "$(BUILD)/release/crt0.o" "$(DESTDIR)/lib"
 	cp -rv "openlibm/include"/* "$(DESTDIR)/include"
 	cp -rv "openlibm/src"/*.h "$(DESTDIR)/include"
 	cp -v "$(BUILD)/openlibm/libopenlibm.a" "$(DESTDIR)/lib/libm.a"
 
-libc: $(BUILD)/release/libc.a $(BUILD)/release/crt0.o
+libc: $(BUILD)/release/libc.a $(BUILD)/release/crt0.o $(BUILD)/include
 
 libm: $(BUILD)/openlibm/libopenlibm.a
 
@@ -65,6 +68,12 @@ $(BUILD)/release/crt0.o: $(SRC)
 	CARGO_INCREMENTAL=0 cargo rustc --release --manifest-path src/crt0/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@
 	touch $@
 
+$(BUILD)/include: $(SRC)
+	rm -rf $@ $@.partial
+	mkdir -p $@.partial
+	./include.sh $@.partial
+	mv $@.partial $@
+
 $(BUILD)/openlibm: openlibm
 	rm -rf $@ $@.partial
 	mkdir -p $(BUILD)
@@ -72,5 +81,5 @@ $(BUILD)/openlibm: openlibm
 	mv $@.partial $@
 	touch $@
 
-$(BUILD)/openlibm/libopenlibm.a: $(BUILD)/openlibm
-	make CC=$(CC) CPPFLAGS="-fno-stack-protector -I$(shell pwd)/include -I $(shell pwd)/target/include" -C $< libopenlibm.a
+$(BUILD)/openlibm/libopenlibm.a: $(BUILD)/openlibm $(BUILD)/include
+	make CC=$(CC) CPPFLAGS="-fno-stack-protector -I$(shell pwd)/include -I $(shell pwd)/$(BUILD)/include" -C $< libopenlibm.a

+ 1 - 0
build.rs

@@ -11,6 +11,7 @@ fn main() {
         .flag("-I")
         .flag(&format!("{}/include", crate_dir))
         .flag("-fno-stack-protector")
+        .flag("-Wno-expansion-to-defined")
         .file("src/c/dlmalloc.c")
         .file("src/c/fcntl.c")
         .file("src/c/stack_chk.c")

+ 1 - 7
fmt.sh

@@ -1,9 +1,3 @@
 #!/usr/bin/env bash
-ARGS=()
 
-for crate in relibc $(find src -name Cargo.toml | cut -d '/' -f2 | grep -v template)
-do
-    ARGS+=("--package" "$crate")
-done
-
-cargo fmt "${ARGS[@]}" "$@"
+cargo fmt --package relibc --package crt0 "$@"

+ 20 - 0
include.sh

@@ -0,0 +1,20 @@
+#!/usr/bin/env bash
+
+set -ex
+
+include="$(realpath "$1")"
+cbindgen="$(realpath cbindgen)"
+
+for config in src/header/*/cbindgen.toml
+do
+    dir="$(dirname "$config")"
+    name="$(basename "$dir")"
+    if [ "${name:0:1}" != "_" ]
+    then
+        header="$include/${name/_/\/}.h"
+        pushd "$dir"
+        cargo run --release --manifest-path "$cbindgen/Cargo.toml" -- \
+            -c cbindgen.toml -o "$header" mod.rs
+        popd
+    fi
+done

+ 0 - 14
src/arpainet/Cargo.toml

@@ -1,14 +0,0 @@
-[package]
-name = "arpainet"
-version = "0.1.0"
-authors = ["Jeremy Soller <jackpot51@gmail.com>"]
-build = "build.rs"
-
-[build-dependencies]
-cbindgen = { path = "../../cbindgen" }
-
-[dependencies]
-platform = { path = "../platform" }
-errno = { path = "../errno" }
-sys_socket = { path = "../sys_socket" }
-netinet = { path = "../netinet" }

+ 0 - 11
src/arpainet/build.rs

@@ -1,11 +0,0 @@
-extern crate cbindgen;
-
-use std::{env, fs};
-
-fn main() {
-    let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set");
-    fs::create_dir_all("../../target/include").expect("failed to create include directory");
-    cbindgen::generate(crate_dir)
-        .expect("failed to generate bindings")
-        .write_to_file("../../target/include/arpa/inet.h");
-}

+ 1255 - 0
src/c_str.rs

@@ -0,0 +1,1255 @@
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use alloc::arc::Arc;
+use alloc::borrow::{Borrow, Cow, ToOwned};
+use alloc::boxed::Box;
+use alloc::rc::Rc;
+use alloc::string::String;
+use alloc::vec::Vec;
+use core::ascii;
+use core::cmp::Ordering;
+use core::fmt::{self, Write};
+use core::mem;
+use core::ops;
+use core::ptr;
+use core::slice;
+use core::str::{self, Utf8Error};
+
+use header::string::strlen;
+use platform::types::*;
+
+pub fn memchr(needle: u8, haystack: &[u8]) -> Option<usize> {
+    use header::string;
+
+    let p = unsafe {
+        string::memchr(
+            haystack.as_ptr() as *const c_void,
+            needle as c_int,
+            haystack.len(),
+        )
+    };
+    if p.is_null() {
+        None
+    } else {
+        Some(p as usize - (haystack.as_ptr() as usize))
+    }
+}
+
+/// A type representing an owned, C-compatible, nul-terminated string with no nul bytes in the
+/// middle.
+///
+/// This type serves the purpose of being able to safely generate a
+/// C-compatible string from a Rust byte slice or vector. An instance of this
+/// type is a static guarantee that the underlying bytes contain no interior 0
+/// bytes ("nul characters") and that the final byte is 0 ("nul terminator").
+///
+/// `CString` is to [`CStr`] as [`String`] is to [`&str`]: the former
+/// in each pair are owned strings; the latter are borrowed
+/// references.
+///
+/// # Creating a `CString`
+///
+/// A `CString` is created from either a byte slice or a byte vector,
+/// or anything that implements [`Into`]`<`[`Vec`]`<`[`u8`]`>>` (for
+/// example, you can build a `CString` straight out of a [`String`] or
+/// a [`&str`], since both implement that trait).
+///
+/// The [`new`] method will actually check that the provided `&[u8]`
+/// does not have 0 bytes in the middle, and return an error if it
+/// finds one.
+///
+/// # Extracting a raw pointer to the whole C string
+///
+/// `CString` implements a [`as_ptr`] method through the [`Deref`]
+/// trait. This method will give you a `*const c_char` which you can
+/// feed directly to extern functions that expect a nul-terminated
+/// string, like C's `strdup()`.
+///
+/// # Extracting a slice of the whole C string
+///
+/// Alternatively, you can obtain a `&[`[`u8`]`]` slice from a
+/// `CString` with the [`as_bytes`] method. Slices produced in this
+/// way do *not* contain the trailing nul terminator. This is useful
+/// when you will be calling an extern function that takes a `*const
+/// u8` argument which is not necessarily nul-terminated, plus another
+/// argument with the length of the string — like C's `strndup()`.
+/// You can of course get the slice's length with its
+/// [`len`][slice.len] method.
+///
+/// If you need a `&[`[`u8`]`]` slice *with* the nul terminator, you
+/// can use [`as_bytes_with_nul`] instead.
+///
+/// Once you have the kind of slice you need (with or without a nul
+/// terminator), you can call the slice's own
+/// [`as_ptr`][slice.as_ptr] method to get a raw pointer to pass to
+/// extern functions. See the documentation for that function for a
+/// discussion on ensuring the lifetime of the raw pointer.
+///
+/// [`Into`]: ../convert/trait.Into.html
+/// [`Vec`]: ../vec/struct.Vec.html
+/// [`String`]: ../string/struct.String.html
+/// [`&str`]: ../primitive.str.html
+/// [`u8`]: ../primitive.u8.html
+/// [`new`]: #method.new
+/// [`as_bytes`]: #method.as_bytes
+/// [`as_bytes_with_nul`]: #method.as_bytes_with_nul
+/// [`as_ptr`]: #method.as_ptr
+/// [slice.as_ptr]: ../primitive.slice.html#method.as_ptr
+/// [slice.len]: ../primitive.slice.html#method.len
+/// [`Deref`]: ../ops/trait.Deref.html
+/// [`CStr`]: struct.CStr.html
+///
+/// # Examples
+///
+/// ```ignore (extern-declaration)
+/// # fn main() {
+/// use std::ffi::CString;
+/// use std::os::raw::c_char;
+///
+/// extern {
+///     fn my_printer(s: *const c_char);
+/// }
+///
+/// // We are certain that our string doesn't have 0 bytes in the middle,
+/// // so we can .unwrap()
+/// let c_to_print = CString::new("Hello, world!").unwrap();
+/// unsafe {
+///     my_printer(c_to_print.as_ptr());
+/// }
+/// # }
+/// ```
+///
+/// # Safety
+///
+/// `CString` is intended for working with traditional C-style strings
+/// (a sequence of non-nul bytes terminated by a single nul byte); the
+/// primary use case for these kinds of strings is interoperating with C-like
+/// code. Often you will need to transfer ownership to/from that external
+/// code. It is strongly recommended that you thoroughly read through the
+/// documentation of `CString` before use, as improper ownership management
+/// of `CString` instances can lead to invalid memory accesses, memory leaks,
+/// and other memory errors.
+
+#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Clone)]
+pub struct CString {
+    // Invariant 1: the slice ends with a zero byte and has a length of at least one.
+    // Invariant 2: the slice contains only one zero byte.
+    // Improper usage of unsafe function can break Invariant 2, but not Invariant 1.
+    inner: Box<[u8]>,
+}
+
+/// Representation of a borrowed C string.
+///
+/// This type represents a borrowed reference to a nul-terminated
+/// array of bytes. It can be constructed safely from a `&[`[`u8`]`]`
+/// slice, or unsafely from a raw `*const c_char`. It can then be
+/// converted to a Rust [`&str`] by performing UTF-8 validation, or
+/// into an owned [`CString`].
+///
+/// `CStr` is to [`CString`] as [`&str`] is to [`String`]: the former
+/// in each pair are borrowed references; the latter are owned
+/// strings.
+///
+/// Note that this structure is **not** `repr(C)` and is not recommended to be
+/// placed in the signatures of FFI functions. Instead, safe wrappers of FFI
+/// functions may leverage the unsafe [`from_ptr`] constructor to provide a safe
+/// interface to other consumers.
+///
+/// # Examples
+///
+/// Inspecting a foreign C string:
+///
+/// ```ignore (extern-declaration)
+/// use std::ffi::CStr;
+/// use std::os::raw::c_char;
+///
+/// extern { fn my_string() -> *const c_char; }
+///
+/// unsafe {
+///     let slice = CStr::from_ptr(my_string());
+///     println!("string buffer size without nul terminator: {}", slice.to_bytes().len());
+/// }
+/// ```
+///
+/// Passing a Rust-originating C string:
+///
+/// ```ignore (extern-declaration)
+/// use std::ffi::{CString, CStr};
+/// use std::os::raw::c_char;
+///
+/// fn work(data: &CStr) {
+///     extern { fn work_with(data: *const c_char); }
+///
+///     unsafe { work_with(data.as_ptr()) }
+/// }
+///
+/// let s = CString::new("data data data data").unwrap();
+/// work(&s);
+/// ```
+///
+/// Converting a foreign C string into a Rust [`String`]:
+///
+/// ```ignore (extern-declaration)
+/// use std::ffi::CStr;
+/// use std::os::raw::c_char;
+///
+/// extern { fn my_string() -> *const c_char; }
+///
+/// fn my_string_safe() -> String {
+///     unsafe {
+///         CStr::from_ptr(my_string()).to_string_lossy().into_owned()
+///     }
+/// }
+///
+/// println!("string: {}", my_string_safe());
+/// ```
+///
+/// [`u8`]: ../primitive.u8.html
+/// [`&str`]: ../primitive.str.html
+/// [`String`]: ../string/struct.String.html
+/// [`CString`]: struct.CString.html
+/// [`from_ptr`]: #method.from_ptr
+#[derive(Hash)]
+pub struct CStr {
+    // FIXME: this should not be represented with a DST slice but rather with
+    //        just a raw `c_char` along with some form of marker to make
+    //        this an unsized type. Essentially `sizeof(&CStr)` should be the
+    //        same as `sizeof(&c_char)` but `CStr` should be an unsized type.
+    inner: [c_char],
+}
+
+/// An error indicating that an interior nul byte was found.
+///
+/// While Rust strings may contain nul bytes in the middle, C strings
+/// can't, as that byte would effectively truncate the string.
+///
+/// This error is created by the [`new`][`CString::new`] method on
+/// [`CString`]. See its documentation for more.
+///
+/// [`CString`]: struct.CString.html
+/// [`CString::new`]: struct.CString.html#method.new
+///
+/// # Examples
+///
+/// ```
+/// use std::ffi::{CString, NulError};
+///
+/// let _: NulError = CString::new(b"f\0oo".to_vec()).unwrap_err();
+/// ```
+#[derive(Clone, PartialEq, Eq, Debug)]
+pub struct NulError(usize, Vec<u8>);
+
+/// An error indicating that a nul byte was not in the expected position.
+///
+/// The slice used to create a [`CStr`] must have one and only one nul
+/// byte at the end of the slice.
+///
+/// This error is created by the
+/// [`from_bytes_with_nul`][`CStr::from_bytes_with_nul`] method on
+/// [`CStr`]. See its documentation for more.
+///
+/// [`CStr`]: struct.CStr.html
+/// [`CStr::from_bytes_with_nul`]: struct.CStr.html#method.from_bytes_with_nul
+///
+/// # Examples
+///
+/// ```
+/// use std::ffi::{CStr, FromBytesWithNulError};
+///
+/// let _: FromBytesWithNulError = CStr::from_bytes_with_nul(b"f\0oo").unwrap_err();
+/// ```
+#[derive(Clone, PartialEq, Eq, Debug)]
+pub struct FromBytesWithNulError {
+    kind: FromBytesWithNulErrorKind,
+}
+
+#[derive(Clone, PartialEq, Eq, Debug)]
+enum FromBytesWithNulErrorKind {
+    InteriorNul(usize),
+    NotNulTerminated,
+}
+
+impl FromBytesWithNulError {
+    fn interior_nul(pos: usize) -> FromBytesWithNulError {
+        FromBytesWithNulError {
+            kind: FromBytesWithNulErrorKind::InteriorNul(pos),
+        }
+    }
+    fn not_nul_terminated() -> FromBytesWithNulError {
+        FromBytesWithNulError {
+            kind: FromBytesWithNulErrorKind::NotNulTerminated,
+        }
+    }
+
+    fn description(&self) -> &str {
+        match self.kind {
+            FromBytesWithNulErrorKind::InteriorNul(..) => {
+                "data provided contains an interior nul byte"
+            }
+            FromBytesWithNulErrorKind::NotNulTerminated => "data provided is not nul terminated",
+        }
+    }
+}
+
+/// An error indicating invalid UTF-8 when converting a [`CString`] into a [`String`].
+///
+/// `CString` is just a wrapper over a buffer of bytes with a nul
+/// terminator; [`into_string`][`CString::into_string`] performs UTF-8
+/// validation on those bytes and may return this error.
+///
+/// This `struct` is created by the
+/// [`into_string`][`CString::into_string`] method on [`CString`]. See
+/// its documentation for more.
+///
+/// [`String`]: ../string/struct.String.html
+/// [`CString`]: struct.CString.html
+/// [`CString::into_string`]: struct.CString.html#method.into_string
+#[derive(Clone, PartialEq, Eq, Debug)]
+pub struct IntoStringError {
+    inner: CString,
+    error: Utf8Error,
+}
+
+impl CString {
+    /// Creates a new C-compatible string from a container of bytes.
+    ///
+    /// This function will consume the provided data and use the
+    /// underlying bytes to construct a new string, ensuring that
+    /// there is a trailing 0 byte. This trailing 0 byte will be
+    /// appended by this function; the provided data should *not*
+    /// contain any 0 bytes in it.
+    ///
+    /// # Examples
+    ///
+    /// ```ignore (extern-declaration)
+    /// use std::ffi::CString;
+    /// use std::os::raw::c_char;
+    ///
+    /// extern { fn puts(s: *const c_char); }
+    ///
+    /// let to_print = CString::new("Hello!").unwrap();
+    /// unsafe {
+    ///     puts(to_print.as_ptr());
+    /// }
+    /// ```
+    ///
+    /// # Errors
+    ///
+    /// This function will return an error if the supplied bytes contain an
+    /// internal 0 byte. The [`NulError`] returned will contain the bytes as well as
+    /// the position of the nul byte.
+    ///
+    /// [`NulError`]: struct.NulError.html
+    pub fn new<T: Into<Vec<u8>>>(t: T) -> Result<CString, NulError> {
+        Self::_new(t.into())
+    }
+
+    fn _new(bytes: Vec<u8>) -> Result<CString, NulError> {
+        match memchr(0, &bytes) {
+            Some(i) => Err(NulError(i, bytes)),
+            None => Ok(unsafe { CString::from_vec_unchecked(bytes) }),
+        }
+    }
+
+    /// Creates a C-compatible string by consuming a byte vector,
+    /// without checking for interior 0 bytes.
+    ///
+    /// This method is equivalent to [`new`] except that no runtime assertion
+    /// is made that `v` contains no 0 bytes, and it requires an actual
+    /// byte vector, not anything that can be converted to one with Into.
+    ///
+    /// [`new`]: #method.new
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use std::ffi::CString;
+    ///
+    /// let raw = b"foo".to_vec();
+    /// unsafe {
+    ///     let c_string = CString::from_vec_unchecked(raw);
+    /// }
+    /// ```
+    pub unsafe fn from_vec_unchecked(mut v: Vec<u8>) -> CString {
+        v.reserve_exact(1);
+        v.push(0);
+        CString {
+            inner: v.into_boxed_slice(),
+        }
+    }
+
+    /// Retakes ownership of a `CString` that was transferred to C via [`into_raw`].
+    ///
+    /// Additionally, the length of the string will be recalculated from the pointer.
+    ///
+    /// # Safety
+    ///
+    /// This should only ever be called with a pointer that was earlier
+    /// obtained by calling [`into_raw`] on a `CString`. Other usage (e.g. trying to take
+    /// ownership of a string that was allocated by foreign code) is likely to lead
+    /// to undefined behavior or allocator corruption.
+    ///
+    /// > **Note:** If you need to borrow a string that was allocated by
+    /// > foreign code, use [`CStr`]. If you need to take ownership of
+    /// > a string that was allocated by foreign code, you will need to
+    /// > make your own provisions for freeing it appropriately, likely
+    /// > with the foreign code's API to do that.
+    ///
+    /// [`into_raw`]: #method.into_raw
+    /// [`CStr`]: struct.CStr.html
+    ///
+    /// # Examples
+    ///
+    /// Create a `CString`, pass ownership to an `extern` function (via raw pointer), then retake
+    /// ownership with `from_raw`:
+    ///
+    /// ```ignore (extern-declaration)
+    /// use std::ffi::CString;
+    /// use std::os::raw::c_char;
+    ///
+    /// extern {
+    ///     fn some_extern_function(s: *mut c_char);
+    /// }
+    ///
+    /// let c_string = CString::new("Hello!").unwrap();
+    /// let raw = c_string.into_raw();
+    /// unsafe {
+    ///     some_extern_function(raw);
+    ///     let c_string = CString::from_raw(raw);
+    /// }
+    /// ```
+    pub unsafe fn from_raw(ptr: *mut c_char) -> CString {
+        let len = strlen(ptr) + 1; // Including the NUL byte
+        let slice = slice::from_raw_parts_mut(ptr, len as usize);
+        CString {
+            inner: Box::from_raw(slice as *mut [c_char] as *mut [u8]),
+        }
+    }
+
+    /// Consumes the `CString` and transfers ownership of the string to a C caller.
+    ///
+    /// The pointer which this function returns must be returned to Rust and reconstituted using
+    /// [`from_raw`] to be properly deallocated. Specifically, one
+    /// should *not* use the standard C `free()` function to deallocate
+    /// this string.
+    ///
+    /// Failure to call [`from_raw`] will lead to a memory leak.
+    ///
+    /// [`from_raw`]: #method.from_raw
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use std::ffi::CString;
+    ///
+    /// let c_string = CString::new("foo").unwrap();
+    ///
+    /// let ptr = c_string.into_raw();
+    ///
+    /// unsafe {
+    ///     assert_eq!(b'f', *ptr as u8);
+    ///     assert_eq!(b'o', *ptr.offset(1) as u8);
+    ///     assert_eq!(b'o', *ptr.offset(2) as u8);
+    ///     assert_eq!(b'\0', *ptr.offset(3) as u8);
+    ///
+    ///     // retake pointer to free memory
+    ///     let _ = CString::from_raw(ptr);
+    /// }
+    /// ```
+    #[inline]
+    pub fn into_raw(self) -> *mut c_char {
+        Box::into_raw(self.into_inner()) as *mut c_char
+    }
+
+    /// Converts the `CString` into a [`String`] if it contains valid UTF-8 data.
+    ///
+    /// On failure, ownership of the original `CString` is returned.
+    ///
+    /// [`String`]: ../string/struct.String.html
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use std::ffi::CString;
+    ///
+    /// let valid_utf8 = vec![b'f', b'o', b'o'];
+    /// let cstring = CString::new(valid_utf8).unwrap();
+    /// assert_eq!(cstring.into_string().unwrap(), "foo");
+    ///
+    /// let invalid_utf8 = vec![b'f', 0xff, b'o', b'o'];
+    /// let cstring = CString::new(invalid_utf8).unwrap();
+    /// let err = cstring.into_string().err().unwrap();
+    /// assert_eq!(err.utf8_error().valid_up_to(), 1);
+    /// ```
+
+    pub fn into_string(self) -> Result<String, IntoStringError> {
+        String::from_utf8(self.into_bytes()).map_err(|e| IntoStringError {
+            error: e.utf8_error(),
+            inner: unsafe { CString::from_vec_unchecked(e.into_bytes()) },
+        })
+    }
+
+    /// Consumes the `CString` and returns the underlying byte buffer.
+    ///
+    /// The returned buffer does **not** contain the trailing nul
+    /// terminator, and it is guaranteed to not have any interior nul
+    /// bytes.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use std::ffi::CString;
+    ///
+    /// let c_string = CString::new("foo").unwrap();
+    /// let bytes = c_string.into_bytes();
+    /// assert_eq!(bytes, vec![b'f', b'o', b'o']);
+    /// ```
+    pub fn into_bytes(self) -> Vec<u8> {
+        let mut vec = self.into_inner().into_vec();
+        let _nul = vec.pop();
+        debug_assert_eq!(_nul, Some(0u8));
+        vec
+    }
+
+    /// Equivalent to the [`into_bytes`] function except that the returned vector
+    /// includes the trailing nul terminator.
+    ///
+    /// [`into_bytes`]: #method.into_bytes
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use std::ffi::CString;
+    ///
+    /// let c_string = CString::new("foo").unwrap();
+    /// let bytes = c_string.into_bytes_with_nul();
+    /// assert_eq!(bytes, vec![b'f', b'o', b'o', b'\0']);
+    /// ```
+    pub fn into_bytes_with_nul(self) -> Vec<u8> {
+        self.into_inner().into_vec()
+    }
+
+    /// Returns the contents of this `CString` as a slice of bytes.
+    ///
+    /// The returned slice does **not** contain the trailing nul
+    /// terminator, and it is guaranteed to not have any interior nul
+    /// bytes. If you need the nul terminator, use
+    /// [`as_bytes_with_nul`] instead.
+    ///
+    /// [`as_bytes_with_nul`]: #method.as_bytes_with_nul
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use std::ffi::CString;
+    ///
+    /// let c_string = CString::new("foo").unwrap();
+    /// let bytes = c_string.as_bytes();
+    /// assert_eq!(bytes, &[b'f', b'o', b'o']);
+    /// ```
+    #[inline]
+    pub fn as_bytes(&self) -> &[u8] {
+        &self.inner[..self.inner.len() - 1]
+    }
+
+    /// Equivalent to the [`as_bytes`] function except that the returned slice
+    /// includes the trailing nul terminator.
+    ///
+    /// [`as_bytes`]: #method.as_bytes
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use std::ffi::CString;
+    ///
+    /// let c_string = CString::new("foo").unwrap();
+    /// let bytes = c_string.as_bytes_with_nul();
+    /// assert_eq!(bytes, &[b'f', b'o', b'o', b'\0']);
+    /// ```
+    #[inline]
+    pub fn as_bytes_with_nul(&self) -> &[u8] {
+        &self.inner
+    }
+
+    /// Extracts a [`CStr`] slice containing the entire string.
+    ///
+    /// [`CStr`]: struct.CStr.html
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use std::ffi::{CString, CStr};
+    ///
+    /// let c_string = CString::new(b"foo".to_vec()).unwrap();
+    /// let c_str = c_string.as_c_str();
+    /// assert_eq!(c_str, CStr::from_bytes_with_nul(b"foo\0").unwrap());
+    /// ```
+    #[inline]
+    pub fn as_c_str(&self) -> &CStr {
+        &*self
+    }
+
+    /// Converts this `CString` into a boxed [`CStr`].
+    ///
+    /// [`CStr`]: struct.CStr.html
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use std::ffi::{CString, CStr};
+    ///
+    /// let c_string = CString::new(b"foo".to_vec()).unwrap();
+    /// let boxed = c_string.into_boxed_c_str();
+    /// assert_eq!(&*boxed, CStr::from_bytes_with_nul(b"foo\0").unwrap());
+    /// ```
+    pub fn into_boxed_c_str(self) -> Box<CStr> {
+        unsafe { Box::from_raw(Box::into_raw(self.into_inner()) as *mut CStr) }
+    }
+
+    // Bypass "move out of struct which implements [`Drop`] trait" restriction.
+    ///
+    /// [`Drop`]: ../ops/trait.Drop.html
+    fn into_inner(self) -> Box<[u8]> {
+        unsafe {
+            let result = ptr::read(&self.inner);
+            mem::forget(self);
+            result
+        }
+    }
+}
+
+// Turns this `CString` into an empty string to prevent
+// memory unsafe code from working by accident. Inline
+// to prevent LLVM from optimizing it away in debug builds.
+impl Drop for CString {
+    #[inline]
+    fn drop(&mut self) {
+        unsafe {
+            *self.inner.get_unchecked_mut(0) = 0;
+        }
+    }
+}
+
+impl ops::Deref for CString {
+    type Target = CStr;
+
+    #[inline]
+    fn deref(&self) -> &CStr {
+        unsafe { CStr::from_bytes_with_nul_unchecked(self.as_bytes_with_nul()) }
+    }
+}
+
+impl fmt::Debug for CString {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        fmt::Debug::fmt(&**self, f)
+    }
+}
+
+impl From<CString> for Vec<u8> {
+    /// Converts a [`CString`] into a [`Vec`]`<u8>`.
+    ///
+    /// The conversion consumes the [`CString`], and removes the terminating NUL byte.
+    ///
+    /// [`Vec`]: ../vec/struct.Vec.html
+    /// [`CString`]: ../ffi/struct.CString.html
+    #[inline]
+    fn from(s: CString) -> Vec<u8> {
+        s.into_bytes()
+    }
+}
+
+impl fmt::Debug for CStr {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        write!(f, "\"")?;
+        for byte in self
+            .to_bytes()
+            .iter()
+            .flat_map(|&b| ascii::escape_default(b))
+        {
+            f.write_char(byte as char)?;
+        }
+        write!(f, "\"")
+    }
+}
+
+impl<'a> Default for &'a CStr {
+    fn default() -> &'a CStr {
+        const SLICE: &'static [c_char] = &[0];
+        unsafe { CStr::from_ptr(SLICE.as_ptr()) }
+    }
+}
+
+impl Default for CString {
+    /// Creates an empty `CString`.
+    fn default() -> CString {
+        let a: &CStr = Default::default();
+        a.to_owned()
+    }
+}
+
+impl Borrow<CStr> for CString {
+    #[inline]
+    fn borrow(&self) -> &CStr {
+        self
+    }
+}
+
+impl<'a> From<Cow<'a, CStr>> for CString {
+    #[inline]
+    fn from(s: Cow<'a, CStr>) -> Self {
+        s.into_owned()
+    }
+}
+
+impl<'a> From<&'a CStr> for Box<CStr> {
+    fn from(s: &'a CStr) -> Box<CStr> {
+        let boxed: Box<[u8]> = Box::from(s.to_bytes_with_nul());
+        unsafe { Box::from_raw(Box::into_raw(boxed) as *mut CStr) }
+    }
+}
+
+impl From<Box<CStr>> for CString {
+    /// Converts a [`Box`]`<CStr>` into a [`CString`] without copying or allocating.
+    ///
+    /// [`Box`]: ../boxed/struct.Box.html
+    /// [`CString`]: ../ffi/struct.CString.html
+    #[inline]
+    fn from(s: Box<CStr>) -> CString {
+        s.into_c_string()
+    }
+}
+
+impl Clone for Box<CStr> {
+    #[inline]
+    fn clone(&self) -> Self {
+        (**self).into()
+    }
+}
+
+impl From<CString> for Box<CStr> {
+    /// Converts a [`CString`] into a [`Box`]`<CStr>` without copying or allocating.
+    ///
+    /// [`CString`]: ../ffi/struct.CString.html
+    /// [`Box`]: ../boxed/struct.Box.html
+    #[inline]
+    fn from(s: CString) -> Box<CStr> {
+        s.into_boxed_c_str()
+    }
+}
+
+impl<'a> From<CString> for Cow<'a, CStr> {
+    #[inline]
+    fn from(s: CString) -> Cow<'a, CStr> {
+        Cow::Owned(s)
+    }
+}
+
+impl<'a> From<&'a CStr> for Cow<'a, CStr> {
+    #[inline]
+    fn from(s: &'a CStr) -> Cow<'a, CStr> {
+        Cow::Borrowed(s)
+    }
+}
+
+impl<'a> From<&'a CString> for Cow<'a, CStr> {
+    #[inline]
+    fn from(s: &'a CString) -> Cow<'a, CStr> {
+        Cow::Borrowed(s.as_c_str())
+    }
+}
+
+impl From<CString> for Arc<CStr> {
+    /// Converts a [`CString`] into a [`Arc`]`<CStr>` without copying or allocating.
+    ///
+    /// [`CString`]: ../ffi/struct.CString.html
+    /// [`Arc`]: ../sync/struct.Arc.html
+    #[inline]
+    fn from(s: CString) -> Arc<CStr> {
+        let arc: Arc<[u8]> = Arc::from(s.into_inner());
+        unsafe { Arc::from_raw(Arc::into_raw(arc) as *const CStr) }
+    }
+}
+
+impl<'a> From<&'a CStr> for Arc<CStr> {
+    #[inline]
+    fn from(s: &CStr) -> Arc<CStr> {
+        let arc: Arc<[u8]> = Arc::from(s.to_bytes_with_nul());
+        unsafe { Arc::from_raw(Arc::into_raw(arc) as *const CStr) }
+    }
+}
+
+impl From<CString> for Rc<CStr> {
+    /// Converts a [`CString`] into a [`Rc`]`<CStr>` without copying or allocating.
+    ///
+    /// [`CString`]: ../ffi/struct.CString.html
+    /// [`Rc`]: ../rc/struct.Rc.html
+    #[inline]
+    fn from(s: CString) -> Rc<CStr> {
+        let rc: Rc<[u8]> = Rc::from(s.into_inner());
+        unsafe { Rc::from_raw(Rc::into_raw(rc) as *const CStr) }
+    }
+}
+
+impl<'a> From<&'a CStr> for Rc<CStr> {
+    #[inline]
+    fn from(s: &CStr) -> Rc<CStr> {
+        let rc: Rc<[u8]> = Rc::from(s.to_bytes_with_nul());
+        unsafe { Rc::from_raw(Rc::into_raw(rc) as *const CStr) }
+    }
+}
+
+impl Default for Box<CStr> {
+    fn default() -> Box<CStr> {
+        let boxed: Box<[u8]> = Box::from([0]);
+        unsafe { Box::from_raw(Box::into_raw(boxed) as *mut CStr) }
+    }
+}
+
+impl NulError {
+    /// Returns the position of the nul byte in the slice that caused
+    /// [`CString::new`] to fail.
+    ///
+    /// [`CString::new`]: struct.CString.html#method.new
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use std::ffi::CString;
+    ///
+    /// let nul_error = CString::new("foo\0bar").unwrap_err();
+    /// assert_eq!(nul_error.nul_position(), 3);
+    ///
+    /// let nul_error = CString::new("foo bar\0").unwrap_err();
+    /// assert_eq!(nul_error.nul_position(), 7);
+    /// ```
+    pub fn nul_position(&self) -> usize {
+        self.0
+    }
+
+    /// Consumes this error, returning the underlying vector of bytes which
+    /// generated the error in the first place.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use std::ffi::CString;
+    ///
+    /// let nul_error = CString::new("foo\0bar").unwrap_err();
+    /// assert_eq!(nul_error.into_vec(), b"foo\0bar");
+    /// ```
+    pub fn into_vec(self) -> Vec<u8> {
+        self.1
+    }
+}
+
+impl fmt::Display for NulError {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        write!(f, "nul byte found in provided data at position: {}", self.0)
+    }
+}
+
+impl fmt::Display for FromBytesWithNulError {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        f.write_str(self.description())?;
+        if let FromBytesWithNulErrorKind::InteriorNul(pos) = self.kind {
+            write!(f, " at byte pos {}", pos)?;
+        }
+        Ok(())
+    }
+}
+
+impl IntoStringError {
+    /// Consumes this error, returning original [`CString`] which generated the
+    /// error.
+    ///
+    /// [`CString`]: struct.CString.html
+    pub fn into_cstring(self) -> CString {
+        self.inner
+    }
+
+    /// Access the underlying UTF-8 error that was the cause of this error.
+    pub fn utf8_error(&self) -> Utf8Error {
+        self.error
+    }
+
+    fn description(&self) -> &str {
+        "C string contained non-utf8 bytes"
+    }
+}
+
+impl fmt::Display for IntoStringError {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        self.description().fmt(f)
+    }
+}
+
+impl CStr {
+    /// Wraps a raw C string with a safe C string wrapper.
+    ///
+    /// This function will wrap the provided `ptr` with a `CStr` wrapper, which
+    /// allows inspection and interoperation of non-owned C strings. This method
+    /// is unsafe for a number of reasons:
+    ///
+    /// * There is no guarantee to the validity of `ptr`.
+    /// * The returned lifetime is not guaranteed to be the actual lifetime of
+    ///   `ptr`.
+    /// * There is no guarantee that the memory pointed to by `ptr` contains a
+    ///   valid nul terminator byte at the end of the string.
+    /// * It is not guaranteed that the memory pointed by `ptr` won't change
+    ///   before the `CStr` has been destroyed.
+    ///
+    /// > **Note**: This operation is intended to be a 0-cost cast but it is
+    /// > currently implemented with an up-front calculation of the length of
+    /// > the string. This is not guaranteed to always be the case.
+    ///
+    /// # Examples
+    ///
+    /// ```ignore (extern-declaration)
+    /// # fn main() {
+    /// use std::ffi::CStr;
+    /// use std::os::raw::c_char;
+    ///
+    /// extern {
+    ///     fn my_string() -> *const c_char;
+    /// }
+    ///
+    /// unsafe {
+    ///     let slice = CStr::from_ptr(my_string());
+    ///     println!("string returned: {}", slice.to_str().unwrap());
+    /// }
+    /// # }
+    /// ```
+    pub unsafe fn from_ptr<'a>(ptr: *const c_char) -> &'a CStr {
+        let len = strlen(ptr);
+        let ptr = ptr as *const u8;
+        CStr::from_bytes_with_nul_unchecked(slice::from_raw_parts(ptr, len as usize + 1))
+    }
+
+    /// Creates a C string wrapper from a byte slice.
+    ///
+    /// This function will cast the provided `bytes` to a `CStr`
+    /// wrapper after ensuring that the byte slice is nul-terminated
+    /// and does not contain any interior nul bytes.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use std::ffi::CStr;
+    ///
+    /// let cstr = CStr::from_bytes_with_nul(b"hello\0");
+    /// assert!(cstr.is_ok());
+    /// ```
+    ///
+    /// Creating a `CStr` without a trailing nul terminator is an error:
+    ///
+    /// ```
+    /// use std::ffi::CStr;
+    ///
+    /// let c_str = CStr::from_bytes_with_nul(b"hello");
+    /// assert!(c_str.is_err());
+    /// ```
+    ///
+    /// Creating a `CStr` with an interior nul byte is an error:
+    ///
+    /// ```
+    /// use std::ffi::CStr;
+    ///
+    /// let c_str = CStr::from_bytes_with_nul(b"he\0llo\0");
+    /// assert!(c_str.is_err());
+    /// ```
+    pub fn from_bytes_with_nul(bytes: &[u8]) -> Result<&CStr, FromBytesWithNulError> {
+        let nul_pos = memchr(0, bytes);
+        if let Some(nul_pos) = nul_pos {
+            if nul_pos + 1 != bytes.len() {
+                return Err(FromBytesWithNulError::interior_nul(nul_pos));
+            }
+            Ok(unsafe { CStr::from_bytes_with_nul_unchecked(bytes) })
+        } else {
+            Err(FromBytesWithNulError::not_nul_terminated())
+        }
+    }
+
+    /// Unsafely creates a C string wrapper from a byte slice.
+    ///
+    /// This function will cast the provided `bytes` to a `CStr` wrapper without
+    /// performing any sanity checks. The provided slice **must** be nul-terminated
+    /// and not contain any interior nul bytes.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use std::ffi::{CStr, CString};
+    ///
+    /// unsafe {
+    ///     let cstring = CString::new("hello").unwrap();
+    ///     let cstr = CStr::from_bytes_with_nul_unchecked(cstring.to_bytes_with_nul());
+    ///     assert_eq!(cstr, &*cstring);
+    /// }
+    /// ```
+    #[inline]
+    pub unsafe fn from_bytes_with_nul_unchecked(bytes: &[u8]) -> &CStr {
+        &*(bytes as *const [u8] as *const CStr)
+    }
+
+    /// Returns the inner pointer to this C string.
+    ///
+    /// The returned pointer will be valid for as long as `self` is, and points
+    /// to a contiguous region of memory terminated with a 0 byte to represent
+    /// the end of the string.
+    ///
+    /// **WARNING**
+    ///
+    /// It is your responsibility to make sure that the underlying memory is not
+    /// freed too early. For example, the following code will cause undefined
+    /// behavior when `ptr` is used inside the `unsafe` block:
+    ///
+    /// ```no_run
+    /// # #![allow(unused_must_use)]
+    /// use std::ffi::{CString};
+    ///
+    /// let ptr = CString::new("Hello").unwrap().as_ptr();
+    /// unsafe {
+    ///     // `ptr` is dangling
+    ///     *ptr;
+    /// }
+    /// ```
+    ///
+    /// This happens because the pointer returned by `as_ptr` does not carry any
+    /// lifetime information and the [`CString`] is deallocated immediately after
+    /// the `CString::new("Hello").unwrap().as_ptr()` expression is evaluated.
+    /// To fix the problem, bind the `CString` to a local variable:
+    ///
+    /// ```no_run
+    /// # #![allow(unused_must_use)]
+    /// use std::ffi::{CString};
+    ///
+    /// let hello = CString::new("Hello").unwrap();
+    /// let ptr = hello.as_ptr();
+    /// unsafe {
+    ///     // `ptr` is valid because `hello` is in scope
+    ///     *ptr;
+    /// }
+    /// ```
+    ///
+    /// This way, the lifetime of the `CString` in `hello` encompasses
+    /// the lifetime of `ptr` and the `unsafe` block.
+    ///
+    /// [`CString`]: struct.CString.html
+    #[inline]
+    pub fn as_ptr(&self) -> *const c_char {
+        self.inner.as_ptr()
+    }
+
+    /// Converts this C string to a byte slice.
+    ///
+    /// The returned slice will **not** contain the trailing nul terminator that this C
+    /// string has.
+    ///
+    /// > **Note**: This method is currently implemented as a constant-time
+    /// > cast, but it is planned to alter its definition in the future to
+    /// > perform the length calculation whenever this method is called.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use std::ffi::CStr;
+    ///
+    /// let c_str = CStr::from_bytes_with_nul(b"foo\0").unwrap();
+    /// assert_eq!(c_str.to_bytes(), b"foo");
+    /// ```
+    #[inline]
+    pub fn to_bytes(&self) -> &[u8] {
+        let bytes = self.to_bytes_with_nul();
+        &bytes[..bytes.len() - 1]
+    }
+
+    /// Converts this C string to a byte slice containing the trailing 0 byte.
+    ///
+    /// This function is the equivalent of [`to_bytes`] except that it will retain
+    /// the trailing nul terminator instead of chopping it off.
+    ///
+    /// > **Note**: This method is currently implemented as a 0-cost cast, but
+    /// > it is planned to alter its definition in the future to perform the
+    /// > length calculation whenever this method is called.
+    ///
+    /// [`to_bytes`]: #method.to_bytes
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use std::ffi::CStr;
+    ///
+    /// let c_str = CStr::from_bytes_with_nul(b"foo\0").unwrap();
+    /// assert_eq!(c_str.to_bytes_with_nul(), b"foo\0");
+    /// ```
+    #[inline]
+    pub fn to_bytes_with_nul(&self) -> &[u8] {
+        unsafe { &*(&self.inner as *const [c_char] as *const [u8]) }
+    }
+
+    /// Yields a [`&str`] slice if the `CStr` contains valid UTF-8.
+    ///
+    /// If the contents of the `CStr` are valid UTF-8 data, this
+    /// function will return the corresponding [`&str`] slice. Otherwise,
+    /// it will return an error with details of where UTF-8 validation failed.
+    ///
+    /// > **Note**: This method is currently implemented to check for validity
+    /// > after a constant-time cast, but it is planned to alter its definition
+    /// > in the future to perform the length calculation in addition to the
+    /// > UTF-8 check whenever this method is called.
+    ///
+    /// [`&str`]: ../primitive.str.html
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use std::ffi::CStr;
+    ///
+    /// let c_str = CStr::from_bytes_with_nul(b"foo\0").unwrap();
+    /// assert_eq!(c_str.to_str(), Ok("foo"));
+    /// ```
+    pub fn to_str(&self) -> Result<&str, str::Utf8Error> {
+        // NB: When CStr is changed to perform the length check in .to_bytes()
+        // instead of in from_ptr(), it may be worth considering if this should
+        // be rewritten to do the UTF-8 check inline with the length calculation
+        // instead of doing it afterwards.
+        str::from_utf8(self.to_bytes())
+    }
+
+    /// Converts a `CStr` into a [`Cow`]`<`[`str`]`>`.
+    ///
+    /// If the contents of the `CStr` are valid UTF-8 data, this
+    /// function will return a [`Cow`]`::`[`Borrowed`]`(`[`&str`]`)`
+    /// with the the corresponding [`&str`] slice. Otherwise, it will
+    /// replace any invalid UTF-8 sequences with
+    /// [`U+FFFD REPLACEMENT CHARACTER`][U+FFFD] and return a
+    /// [`Cow`]`::`[`Owned`]`(`[`String`]`)` with the result.
+    ///
+    /// > **Note**: This method is currently implemented to check for validity
+    /// > after a constant-time cast, but it is planned to alter its definition
+    /// > in the future to perform the length calculation in addition to the
+    /// > UTF-8 check whenever this method is called.
+    ///
+    /// [`Cow`]: ../borrow/enum.Cow.html
+    /// [`Borrowed`]: ../borrow/enum.Cow.html#variant.Borrowed
+    /// [`Owned`]: ../borrow/enum.Cow.html#variant.Owned
+    /// [`str`]: ../primitive.str.html
+    /// [`String`]: ../string/struct.String.html
+    /// [U+FFFD]: ../char/constant.REPLACEMENT_CHARACTER.html
+    ///
+    /// # Examples
+    ///
+    /// Calling `to_string_lossy` on a `CStr` containing valid UTF-8:
+    ///
+    /// ```
+    /// use std::borrow::Cow;
+    /// use std::ffi::CStr;
+    ///
+    /// let c_str = CStr::from_bytes_with_nul(b"Hello World\0").unwrap();
+    /// assert_eq!(c_str.to_string_lossy(), Cow::Borrowed("Hello World"));
+    /// ```
+    ///
+    /// Calling `to_string_lossy` on a `CStr` containing invalid UTF-8:
+    ///
+    /// ```
+    /// use std::borrow::Cow;
+    /// use std::ffi::CStr;
+    ///
+    /// let c_str = CStr::from_bytes_with_nul(b"Hello \xF0\x90\x80World\0").unwrap();
+    /// assert_eq!(
+    ///     c_str.to_string_lossy(),
+    ///     Cow::Owned(String::from("Hello �World")) as Cow<str>
+    /// );
+    /// ```
+    pub fn to_string_lossy(&self) -> Cow<str> {
+        String::from_utf8_lossy(self.to_bytes())
+    }
+
+    /// Converts a [`Box`]`<CStr>` into a [`CString`] without copying or allocating.
+    ///
+    /// [`Box`]: ../boxed/struct.Box.html
+    /// [`CString`]: struct.CString.html
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use std::ffi::CString;
+    ///
+    /// let c_string = CString::new(b"foo".to_vec()).unwrap();
+    /// let boxed = c_string.into_boxed_c_str();
+    /// assert_eq!(boxed.into_c_string(), CString::new("foo").unwrap());
+    /// ```
+    pub fn into_c_string(self: Box<CStr>) -> CString {
+        let raw = Box::into_raw(self) as *mut [u8];
+        CString {
+            inner: unsafe { Box::from_raw(raw) },
+        }
+    }
+}
+
+impl PartialEq for CStr {
+    fn eq(&self, other: &CStr) -> bool {
+        self.to_bytes().eq(other.to_bytes())
+    }
+}
+
+impl Eq for CStr {}
+
+impl PartialOrd for CStr {
+    fn partial_cmp(&self, other: &CStr) -> Option<Ordering> {
+        self.to_bytes().partial_cmp(&other.to_bytes())
+    }
+}
+
+impl Ord for CStr {
+    fn cmp(&self, other: &CStr) -> Ordering {
+        self.to_bytes().cmp(&other.to_bytes())
+    }
+}
+
+impl ToOwned for CStr {
+    type Owned = CString;
+
+    fn to_owned(&self) -> CString {
+        CString {
+            inner: self.to_bytes_with_nul().into(),
+        }
+    }
+}
+
+impl<'a> From<&'a CStr> for CString {
+    fn from(s: &'a CStr) -> CString {
+        s.to_owned()
+    }
+}
+
+impl ops::Index<ops::RangeFull> for CString {
+    type Output = CStr;
+
+    #[inline]
+    fn index(&self, _index: ops::RangeFull) -> &CStr {
+        self
+    }
+}
+
+impl AsRef<CStr> for CStr {
+    #[inline]
+    fn as_ref(&self) -> &CStr {
+        self
+    }
+}
+
+impl AsRef<CStr> for CString {
+    #[inline]
+    fn as_ref(&self) -> &CStr {
+        self
+    }
+}

+ 1 - 2
src/crt0/Cargo.toml

@@ -8,5 +8,4 @@ name = "crt0"
 crate-type = ["staticlib"]
 
 [dependencies]
-platform = { path = "../platform" }
-stdio = { path = "../stdio" }
+relibc = { path = "../.." }

+ 8 - 100
src/crt0/src/lib.rs

@@ -1,20 +1,11 @@
 //! crt0
 
 #![no_std]
-#![feature(alloc)]
 #![feature(asm)]
+#![feature(lang_items)]
 #![feature(linkage)]
 #![feature(naked_functions)]
 #![feature(panic_implementation)]
-#![feature(lang_items)]
-
-extern crate alloc;
-extern crate platform;
-extern crate stdio;
-
-use alloc::Vec;
-use core::ptr;
-use platform::types::*;
 
 #[no_mangle]
 #[naked]
@@ -22,7 +13,7 @@ pub unsafe extern "C" fn _start() {
     #[cfg(target_arch = "x86_64")]
     asm!("mov rdi, rsp
         and rsp, 0xFFFFFFFFFFFFFFF0
-        call _start_rust"
+        call relibc_start"
         :
         :
         :
@@ -30,7 +21,7 @@ pub unsafe extern "C" fn _start() {
     );
     #[cfg(target_arch = "aarch64")]
     asm!("mov x0, sp
-        bl _start_rust"
+        bl relibc_start"
         :
         :
         :
@@ -38,96 +29,13 @@ pub unsafe extern "C" fn _start() {
     );
 }
 
-#[repr(C)]
-pub struct Stack {
-    argc: isize,
-    argv0: *const c_char,
-}
-
-impl Stack {
-    fn argc(&self) -> isize {
-        self.argc
-    }
-
-    fn argv(&self) -> *const *const c_char {
-        &self.argv0 as *const _
-    }
-
-    fn envp(&self) -> *const *const c_char {
-        unsafe { self.argv().offset(self.argc() + 1) }
-    }
-}
-
-#[inline(never)]
-#[no_mangle]
-pub unsafe extern "C" fn _start_rust(sp: &'static Stack) -> ! {
-    extern "C" {
-        fn main(argc: isize, argv: *const *const c_char, envp: *const *const c_char) -> c_int;
-    }
-
-    let argc = sp.argc();
-    let argv = sp.argv();
-
-    let envp = sp.envp();
-    let mut len = 0;
-    while *envp.offset(len) != ptr::null() {
-        len += 1;
-    }
-    platform::inner_environ = Vec::with_capacity(len as usize + 1);
-    for i in 0..len {
-        let mut item = *envp.offset(i);
-        let mut len = 0;
-        while *item.offset(len) != 0 {
-            len += 1;
-        }
-
-        let buf = platform::alloc(len as usize + 1) as *mut c_char;
-        for i in 0..=len {
-            *buf.offset(i) = *item.offset(i);
-        }
-        platform::inner_environ.push(buf);
-    }
-    platform::inner_environ.push(ptr::null_mut());
-    platform::environ = platform::inner_environ.as_mut_ptr();
-
-    // Initialize stdin/stdout/stderr, see https://github.com/rust-lang/rust/issues/51718
-    stdio::stdin = stdio::default_stdin.get();
-    stdio::stdout = stdio::default_stdout.get();
-    stdio::stderr = stdio::default_stderr.get();
-
-    platform::exit(main(
-        argc,
-        argv,
-        // not envp, because programs like bash try to modify this *const*
-        // pointer :|
-        platform::environ as *const *const c_char
-    ));
-}
-
 #[panic_implementation]
 #[linkage = "weak"]
 #[no_mangle]
-pub extern "C" fn rust_begin_unwind(pi: &::core::panic::PanicInfo) -> ! {
-    use core::fmt::Write;
-
-    let mut w = platform::FileWriter(2);
-    let _ = w.write_fmt(format_args!("RELIBC CRT0 PANIC: {}\n", pi));
-
-    platform::exit(1);
-}
-
-#[lang = "oom"]
-#[linkage = "weak"]
-#[no_mangle]
-pub extern "C" fn rust_oom(layout: ::core::alloc::Layout) -> ! {
-    use core::fmt::Write;
-
-    let mut w = platform::FileWriter(2);
-    let _ = w.write_fmt(format_args!(
-        "RELIBC OOM: {} bytes aligned to {} bytes\n",
-        layout.size(),
-        layout.align()
-    ));
+pub extern "C" fn rust_begin_unwind(_pi: &::core::panic::PanicInfo) -> ! {
+    extern "C" {
+        fn exit(status: i32) -> !;
+    }
 
-    platform::exit(1);
+    unsafe { exit(1) }
 }

+ 0 - 11
src/ctype/Cargo.toml

@@ -1,11 +0,0 @@
-[package]
-name = "ctype"
-version = "0.1.0"
-authors = ["Jeremy Soller <jackpot51@gmail.com>"]
-build = "build.rs"
-
-[build-dependencies]
-cbindgen = { path = "../../cbindgen" }
-
-[dependencies]
-platform = { path = "../platform" }

+ 0 - 11
src/ctype/build.rs

@@ -1,11 +0,0 @@
-extern crate cbindgen;
-
-use std::{env, fs};
-
-fn main() {
-    let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set");
-    fs::create_dir_all("../../target/include").expect("failed to create include directory");
-    cbindgen::generate(crate_dir)
-        .expect("failed to generate bindings")
-        .write_to_file("../../target/include/ctype.h");
-}

+ 0 - 15
src/dirent/Cargo.toml

@@ -1,15 +0,0 @@
-[package]
-name = "dirent"
-version = "0.1.0"
-authors = ["jD91mZM2 <me@krake.one>"]
-build = "build.rs"
-
-[build-dependencies]
-cbindgen = { path = "../../cbindgen" }
-
-[dependencies]
-errno = { path = "../errno" }
-fcntl = { path = "../fcntl" }
-platform = { path = "../platform" }
-stdio = { path = "../stdio" }
-unistd = { path = "../unistd" }

+ 0 - 11
src/dirent/build.rs

@@ -1,11 +0,0 @@
-extern crate cbindgen;
-
-use std::{env, fs};
-
-fn main() {
-    let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set");
-    fs::create_dir_all("../../target/include").expect("failed to create include directory");
-    cbindgen::generate(crate_dir)
-        .expect("failed to generate bindings")
-        .write_to_file("../../target/include/dirent.h");
-}

+ 0 - 11
src/errno/Cargo.toml

@@ -1,11 +0,0 @@
-[package]
-name = "errno"
-version = "0.1.0"
-authors = ["Alex Lyon <arcterus@mail.com>"]
-build = "build.rs"
-
-[build-dependencies]
-cbindgen = { path = "../../cbindgen" }
-
-[dependencies]
-platform = { path = "../platform" }

+ 0 - 11
src/errno/build.rs

@@ -1,11 +0,0 @@
-extern crate cbindgen;
-
-use std::{env, fs};
-
-fn main() {
-    let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set");
-    fs::create_dir_all("../../target/include").expect("failed to create include directory");
-    cbindgen::generate(crate_dir)
-        .expect("failed to generate bindings")
-        .write_to_file("../../target/include/errno.h");
-}

+ 0 - 11
src/fcntl/Cargo.toml

@@ -1,11 +0,0 @@
-[package]
-name = "fcntl"
-version = "0.1.0"
-authors = ["Jeremy Soller <jackpot51@gmail.com>"]
-build = "build.rs"
-
-[build-dependencies]
-cbindgen = { path = "../../cbindgen" }
-
-[dependencies]
-platform = { path = "../platform" }

+ 0 - 11
src/fcntl/build.rs

@@ -1,11 +0,0 @@
-extern crate cbindgen;
-
-use std::{env, fs};
-
-fn main() {
-    let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set");
-    fs::create_dir_all("../../target/include").expect("failed to create include directory");
-    cbindgen::generate(crate_dir)
-        .expect("failed to generate bindings")
-        .write_to_file("../../target/include/fcntl.h");
-}

+ 0 - 13
src/fcntl/src/linux.rs

@@ -1,13 +0,0 @@
-use platform::types::*;
-
-pub const O_RDONLY: c_int = 0x0000;
-pub const O_WRONLY: c_int = 0x0001;
-pub const O_RDWR: c_int = 0x0002;
-pub const O_CREAT: c_int = 0x0040;
-pub const O_TRUNC: c_int = 0x0200;
-pub const O_ACCMODE: c_int = O_RDONLY | O_WRONLY | O_RDWR;
-pub const O_APPEND: c_int = 0o2000;
-pub const O_CLOEXEC: c_int = 0o2_000_000;
-pub const O_DIRECTORY: c_int = 0o200_000;
-pub const O_EXCL: c_int = 0o200;
-pub const O_NONBLOCK: c_int = 0o4000;

+ 0 - 10
src/fenv/Cargo.toml

@@ -1,10 +0,0 @@
-[package]
-name = "fenv"
-version = "0.1.0"
-authors = ["Dan Robertson <danlrobertson89@gmail.com>"]
-
-[build-dependencies]
-cbindgen = { path = "../../cbindgen" }
-
-[dependencies]
-platform = { path = "../platform" }

+ 0 - 11
src/fenv/build.rs

@@ -1,11 +0,0 @@
-extern crate cbindgen;
-
-use std::{env, fs};
-
-fn main() {
-    let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set");
-    fs::create_dir_all("../../target/include").expect("failed to create include directory");
-    cbindgen::generate(crate_dir)
-        .expect("failed to generate bindings")
-        .write_to_file("../../target/include/fenv.h");
-}

+ 0 - 11
src/float/Cargo.toml

@@ -1,11 +0,0 @@
-[package]
-name = "float"
-version = "0.1.0"
-authors = ["Dan Robertson <danlrobertson89@gmail.com>"]
-
-[build-dependencies]
-cbindgen = { path = "../../cbindgen" }
-
-[dependencies]
-platform = { path = "../platform" }
-fenv = { path = "../fenv" }

+ 0 - 11
src/float/build.rs

@@ -1,11 +0,0 @@
-extern crate cbindgen;
-
-use std::{env, fs};
-
-fn main() {
-    let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set");
-    fs::create_dir_all("../../target/include").expect("failed to create include directory");
-    cbindgen::generate(crate_dir)
-        .expect("failed to generate bindings")
-        .write_to_file("../../target/include/float.h");
-}

+ 0 - 10
src/fnmatch/Cargo.toml

@@ -1,10 +0,0 @@
-[package]
-name = "fnmatch"
-version = "0.1.0"
-authors = ["jD91mZM2 <me@krake.one>"]
-
-[build-dependencies]
-cbindgen = { path = "../../cbindgen" }
-
-[dependencies]
-platform = { path = "../platform" }

+ 0 - 11
src/fnmatch/build.rs

@@ -1,11 +0,0 @@
-extern crate cbindgen;
-
-use std::{env, fs};
-
-fn main() {
-    let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set");
-    fs::create_dir_all("../../target/include").expect("failed to create include directory");
-    cbindgen::generate(crate_dir)
-      .expect("failed to generate bindings")
-      .write_to_file("../../target/include/fnmatch.h");
-}

+ 0 - 11
src/grp/Cargo.toml

@@ -1,11 +0,0 @@
-[package]
-name = "grp"
-version = "0.1.0"
-authors = ["Jeremy Soller <jackpot51@gmail.com>"]
-build = "build.rs"
-
-[build-dependencies]
-cbindgen = { path = "../../cbindgen" }
-
-[dependencies]
-platform = { path = "../platform" }

+ 0 - 11
src/grp/build.rs

@@ -1,11 +0,0 @@
-extern crate cbindgen;
-
-use std::{env, fs};
-
-fn main() {
-    let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set");
-    fs::create_dir_all("../../target/include").expect("failed to create include directory");
-    cbindgen::generate(crate_dir)
-        .expect("failed to generate bindings")
-        .write_to_file("../../target/include/grp.h");
-}

+ 0 - 0
src/todo/oldlib/dns/answer.rs → src/header/_oldlib/dns/answer.rs


+ 0 - 0
src/todo/oldlib/dns/mod.rs → src/header/_oldlib/dns/mod.rs


+ 0 - 0
src/todo/oldlib/dns/query.rs → src/header/_oldlib/dns/query.rs


+ 0 - 0
src/todo/oldlib/event.rs → src/header/_oldlib/event.rs


+ 0 - 0
src/todo/oldlib/file.rs → src/header/_oldlib/file.rs


+ 0 - 0
src/todo/oldlib/folder.rs → src/header/_oldlib/folder.rs


+ 0 - 0
src/todo/oldlib/hostname.rs → src/header/_oldlib/hostname.rs


+ 0 - 0
src/todo/oldlib/lib.rs → src/header/_oldlib/lib.rs


+ 0 - 0
src/todo/oldlib/macros.rs → src/header/_oldlib/macros.rs


+ 0 - 0
src/todo/oldlib/mallocnull.rs → src/header/_oldlib/mallocnull.rs


+ 0 - 0
src/todo/oldlib/netdb.rs → src/header/_oldlib/netdb.rs


+ 0 - 0
src/todo/oldlib/process.rs → src/header/_oldlib/process.rs


+ 0 - 0
src/todo/oldlib/rawfile.rs → src/header/_oldlib/rawfile.rs


+ 0 - 0
src/todo/oldlib/redox.rs → src/header/_oldlib/redox.rs


+ 0 - 0
src/todo/oldlib/socket.rs → src/header/_oldlib/socket.rs


+ 0 - 0
src/todo/oldlib/termios.rs → src/header/_oldlib/termios.rs


+ 0 - 0
src/todo/oldlib/time.rs → src/header/_oldlib/time.rs


+ 0 - 0
src/todo/oldlib/types.rs → src/header/_oldlib/types.rs


+ 0 - 0
src/todo/oldlib/unimpl.rs → src/header/_oldlib/unimpl.rs


+ 0 - 0
src/todo/oldlib/user.rs → src/header/_oldlib/user.rs


+ 7 - 0
src/header/_pthread/cbindgen.toml

@@ -0,0 +1,7 @@
+sys_includes = []
+include_guard = "_PTHREAD_H"
+language = "C"
+style = "Tag"
+
+[enum]
+prefix_with_name = true

+ 119 - 147
src/todo/pthread/lib.rs → src/header/_pthread/mod.rs

@@ -1,13 +1,26 @@
+use platform::types::*;
+
+#[repr(C)]
+#[derive(Debug, Copy)]
+pub struct sched_param {
+    pub _address: u8,
+}
+impl Clone for sched_param {
+    fn clone(&self) -> Self {
+        *self
+    }
+}
+
 // #[no_mangle]
-pub extern "C" fn pthread_attr_destroy(attr: *mut pthread_attr_t) -> libc::c_int {
+pub extern "C" fn pthread_attr_destroy(attr: *mut pthread_attr_t) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
 pub extern "C" fn pthread_attr_getdetachstate(
     attr: *const pthread_attr_t,
-    detachstate: *mut libc::c_int,
-) -> libc::c_int {
+    detachstate: *mut c_int,
+) -> c_int {
     unimplemented!();
 }
 
@@ -15,15 +28,15 @@ pub extern "C" fn pthread_attr_getdetachstate(
 pub extern "C" fn pthread_attr_getguardsize(
     attr: *const pthread_attr_t,
     guardsize: *mut usize,
-) -> libc::c_int {
+) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
 pub extern "C" fn pthread_attr_getinheritsched(
     attr: *const pthread_attr_t,
-    inheritsched: *mut libc::c_int,
-) -> libc::c_int {
+    inheritsched: *mut c_int,
+) -> c_int {
     unimplemented!();
 }
 
@@ -31,31 +44,31 @@ pub extern "C" fn pthread_attr_getinheritsched(
 pub extern "C" fn pthread_attr_getschedparam(
     attr: *const pthread_attr_t,
     param: *mut sched_param,
-) -> libc::c_int {
+) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
 pub extern "C" fn pthread_attr_getschedpolicy(
     attr: *const pthread_attr_t,
-    policy: *mut libc::c_int,
-) -> libc::c_int {
+    policy: *mut c_int,
+) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
 pub extern "C" fn pthread_attr_getscope(
     attr: *const pthread_attr_t,
-    contentionscope: *mut libc::c_int,
-) -> libc::c_int {
+    contentionscope: *mut c_int,
+) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
 pub extern "C" fn pthread_attr_getstackaddr(
     attr: *const pthread_attr_t,
-    stackaddr: *mut *mut libc::c_void,
-) -> libc::c_int {
+    stackaddr: *mut *mut c_void,
+) -> c_int {
     unimplemented!();
 }
 
@@ -63,33 +76,33 @@ pub extern "C" fn pthread_attr_getstackaddr(
 pub extern "C" fn pthread_attr_getstacksize(
     attr: *const pthread_attr_t,
     stacksize: *mut usize,
-) -> libc::c_int {
+) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn pthread_attr_init(arg1: *mut pthread_attr_t) -> libc::c_int {
+pub extern "C" fn pthread_attr_init(arg1: *mut pthread_attr_t) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
 pub extern "C" fn pthread_attr_setdetachstate(
     attr: *mut pthread_attr_t,
-    detachstate: libc::c_int,
-) -> libc::c_int {
+    detachstate: c_int,
+) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn pthread_attr_setguardsize(arg1: *mut pthread_attr_t, arg2: usize) -> libc::c_int {
+pub extern "C" fn pthread_attr_setguardsize(arg1: *mut pthread_attr_t, arg2: usize) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
 pub extern "C" fn pthread_attr_setinheritsched(
     attr: *mut pthread_attr_t,
-    inheritsched: libc::c_int,
-) -> libc::c_int {
+    inheritsched: c_int,
+) -> c_int {
     unimplemented!();
 }
 
@@ -97,61 +110,61 @@ pub extern "C" fn pthread_attr_setinheritsched(
 pub extern "C" fn pthread_attr_setschedparam(
     attr: *mut pthread_attr_t,
     param: *mut sched_param,
-) -> libc::c_int {
+) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
 pub extern "C" fn pthread_attr_setschedpolicy(
     attr: *mut pthread_attr_t,
-    policy: libc::c_int,
-) -> libc::c_int {
+    policy: c_int,
+) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
 pub extern "C" fn pthread_attr_setscope(
     attr: *mut pthread_attr_t,
-    contentionscope: libc::c_int,
-) -> libc::c_int {
+    contentionscope: c_int,
+) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
 pub extern "C" fn pthread_attr_setstackaddr(
     attr: *mut pthread_attr_t,
-    stackaddr: *mut libc::c_void,
-) -> libc::c_int {
+    stackaddr: *mut c_void,
+) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn pthread_attr_setstacksize(attr: *mut pthread_attr_t, stacksize: usize) -> libc::c_int {
+pub extern "C" fn pthread_attr_setstacksize(attr: *mut pthread_attr_t, stacksize: usize) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn pthread_cancel(thread: pthread_t) -> libc::c_int {
+pub extern "C" fn pthread_cancel(thread: pthread_t) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn pthread_cleanup_push(routine: *mut libc::c_void, arg: *mut libc::c_void) {
+pub extern "C" fn pthread_cleanup_push(routine: *mut c_void, arg: *mut c_void) {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn pthread_cleanup_pop(execute: libc::c_int) {
+pub extern "C" fn pthread_cleanup_pop(execute: c_int) {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn pthread_cond_broadcast(cond: *mut pthread_cond_t) -> libc::c_int {
+pub extern "C" fn pthread_cond_broadcast(cond: *mut pthread_cond_t) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn pthread_cond_destroy(cond: *mut pthread_cond_t) -> libc::c_int {
+pub extern "C" fn pthread_cond_destroy(cond: *mut pthread_cond_t) -> c_int {
     unimplemented!();
 }
 
@@ -159,12 +172,12 @@ pub extern "C" fn pthread_cond_destroy(cond: *mut pthread_cond_t) -> libc::c_int
 pub extern "C" fn pthread_cond_init(
     cond: *mut pthread_cond_t,
     attr: *const pthread_condattr_t,
-) -> libc::c_int {
+) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn pthread_cond_signal(cond: *mut pthread_cond_t) -> libc::c_int {
+pub extern "C" fn pthread_cond_signal(cond: *mut pthread_cond_t) -> c_int {
     unimplemented!();
 }
 
@@ -173,7 +186,7 @@ pub extern "C" fn pthread_cond_timedwait(
     cond: *mut pthread_cond_t,
     mutex: *mut pthread_mutex_t,
     abstime: *const timespec,
-) -> libc::c_int {
+) -> c_int {
     unimplemented!();
 }
 
@@ -181,33 +194,33 @@ pub extern "C" fn pthread_cond_timedwait(
 pub extern "C" fn pthread_cond_wait(
     cond: *mut pthread_cond_t,
     mutex: *mut pthread_mutex_t,
-) -> libc::c_int {
+) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn pthread_condattr_destroy(attr: *mut pthread_condattr_t) -> libc::c_int {
+pub extern "C" fn pthread_condattr_destroy(attr: *mut pthread_condattr_t) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
 pub extern "C" fn pthread_condattr_getpshared(
     attr: *const pthread_condattr_t,
-    pshared: *mut libc::c_int,
-) -> libc::c_int {
+    pshared: *mut c_int,
+) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn pthread_condattr_init(attr: *mut pthread_condattr_t) -> libc::c_int {
+pub extern "C" fn pthread_condattr_init(attr: *mut pthread_condattr_t) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
 pub extern "C" fn pthread_condattr_setpshared(
     attr: *mut pthread_condattr_t,
-    pshared: libc::c_int,
-) -> libc::c_int {
+    pshared: c_int,
+) -> c_int {
     unimplemented!();
 }
 
@@ -215,74 +228,74 @@ pub extern "C" fn pthread_condattr_setpshared(
 pub extern "C" fn pthread_create(
     thread: *mut pthread_t,
     attr: *const pthread_attr_t,
-    start_routine: Option<unsafe extern "C" fn(arg1: *mut libc::c_void) -> *mut libc::c_void>,
-    arg: *mut libc::c_void,
-) -> libc::c_int {
+    start_routine: Option<unsafe extern "C" fn(arg1: *mut c_void) -> *mut c_void>,
+    arg: *mut c_void,
+) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn pthread_detach(thread: pthread_t) -> libc::c_int {
+pub extern "C" fn pthread_detach(thread: pthread_t) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn pthread_equal(t1: pthread_t, t2: pthread_t) -> libc::c_int {
+pub extern "C" fn pthread_equal(t1: pthread_t, t2: pthread_t) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn pthread_exit(value_ptr: *mut libc::c_void) {
+pub extern "C" fn pthread_exit(value_ptr: *mut c_void) {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn pthread_getconcurrency() -> libc::c_int {
+pub extern "C" fn pthread_getconcurrency() -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
 pub extern "C" fn pthread_getschedparam(
     thread: pthread_t,
-    policy: *mut libc::c_int,
+    policy: *mut c_int,
     param: *mut sched_param,
-) -> libc::c_int {
+) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn pthread_getspecific(key: pthread_key_t) -> *mut libc::c_void {
+pub extern "C" fn pthread_getspecific(key: pthread_key_t) -> *mut c_void {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn pthread_join(thread: pthread_t, value_ptr: *mut *mut libc::c_void) -> libc::c_int {
+pub extern "C" fn pthread_join(thread: pthread_t, value_ptr: *mut *mut c_void) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
 pub extern "C" fn pthread_key_create(
     key: *mut pthread_key_t,
-    destructor: Option<unsafe extern "C" fn(arg1: *mut libc::c_void)>,
-) -> libc::c_int {
+    destructor: Option<unsafe extern "C" fn(arg1: *mut c_void)>,
+) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn pthread_key_delete(key: pthread_key_t) -> libc::c_int {
+pub extern "C" fn pthread_key_delete(key: pthread_key_t) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn pthread_mutex_destroy(mutex: *mut pthread_mutex_t) -> libc::c_int {
+pub extern "C" fn pthread_mutex_destroy(mutex: *mut pthread_mutex_t) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
 pub extern "C" fn pthread_mutex_getprioceiling(
     mutex: *const pthread_mutex_t,
-    prioceiling: *mut libc::c_int,
-) -> libc::c_int {
+    prioceiling: *mut c_int,
+) -> c_int {
     unimplemented!();
 }
 
@@ -290,105 +303,105 @@ pub extern "C" fn pthread_mutex_getprioceiling(
 pub extern "C" fn pthread_mutex_init(
     mutex: *mut pthread_mutex_t,
     attr: *const pthread_mutexattr_t,
-) -> libc::c_int {
+) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn pthread_mutex_lock(mutex: *mut pthread_mutex_t) -> libc::c_int {
+pub extern "C" fn pthread_mutex_lock(mutex: *mut pthread_mutex_t) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
 pub extern "C" fn pthread_mutex_setprioceiling(
     mutex: *mut pthread_mutex_t,
-    prioceiling: libc::c_int,
-    old_ceiling: *mut libc::c_int,
-) -> libc::c_int {
+    prioceiling: c_int,
+    old_ceiling: *mut c_int,
+) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn pthread_mutex_trylock(mutex: *mut pthread_mutex_t) -> libc::c_int {
+pub extern "C" fn pthread_mutex_trylock(mutex: *mut pthread_mutex_t) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn pthread_mutex_unlock(mutex: *mut pthread_mutex_t) -> libc::c_int {
+pub extern "C" fn pthread_mutex_unlock(mutex: *mut pthread_mutex_t) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn pthread_mutexattr_destroy(attr: *mut pthread_mutexattr_t) -> libc::c_int {
+pub extern "C" fn pthread_mutexattr_destroy(attr: *mut pthread_mutexattr_t) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
 pub extern "C" fn pthread_mutexattr_getprioceiling(
     attr: *const pthread_mutexattr_t,
-    prioceiling: *mut libc::c_int,
-) -> libc::c_int {
+    prioceiling: *mut c_int,
+) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
 pub extern "C" fn pthread_mutexattr_getprotocol(
     attr: *const pthread_mutexattr_t,
-    protocol: *mut libc::c_int,
-) -> libc::c_int {
+    protocol: *mut c_int,
+) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
 pub extern "C" fn pthread_mutexattr_getpshared(
     attr: *const pthread_mutexattr_t,
-    pshared: *mut libc::c_int,
-) -> libc::c_int {
+    pshared: *mut c_int,
+) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
 pub extern "C" fn pthread_mutexattr_gettype(
     attr: *const pthread_mutexattr_t,
-    type_: *mut libc::c_int,
-) -> libc::c_int {
+    type_: *mut c_int,
+) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn pthread_mutexattr_init(attr: *mut pthread_mutexattr_t) -> libc::c_int {
+pub extern "C" fn pthread_mutexattr_init(attr: *mut pthread_mutexattr_t) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
 pub extern "C" fn pthread_mutexattr_setprioceiling(
     attr: *mut pthread_mutexattr_t,
-    prioceiling: libc::c_int,
-) -> libc::c_int {
+    prioceiling: c_int,
+) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
 pub extern "C" fn pthread_mutexattr_setprotocol(
     attr: *mut pthread_mutexattr_t,
-    protocol: libc::c_int,
-) -> libc::c_int {
+    protocol: c_int,
+) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
 pub extern "C" fn pthread_mutexattr_setpshared(
     attr: *mut pthread_mutexattr_t,
-    pshared: libc::c_int,
-) -> libc::c_int {
+    pshared: c_int,
+) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
 pub extern "C" fn pthread_mutexattr_settype(
     attr: *mut pthread_mutexattr_t,
-    type_: libc::c_int,
-) -> libc::c_int {
+    type_: c_int,
+) -> c_int {
     unimplemented!();
 }
 
@@ -396,12 +409,12 @@ pub extern "C" fn pthread_mutexattr_settype(
 pub extern "C" fn pthread_once(
     once_control: *mut pthread_once_t,
     init_routine: Option<unsafe extern "C" fn()>,
-) -> libc::c_int {
+) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn pthread_rwlock_destroy(rwlock: *mut pthread_rwlock_t) -> libc::c_int {
+pub extern "C" fn pthread_rwlock_destroy(rwlock: *mut pthread_rwlock_t) -> c_int {
     unimplemented!();
 }
 
@@ -409,58 +422,58 @@ pub extern "C" fn pthread_rwlock_destroy(rwlock: *mut pthread_rwlock_t) -> libc:
 pub extern "C" fn pthread_rwlock_init(
     rwlock: *mut pthread_rwlock_t,
     attr: *const pthread_rwlockattr_t,
-) -> libc::c_int {
+) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn pthread_rwlock_rdlock(rwlock: *mut pthread_rwlock_t) -> libc::c_int {
+pub extern "C" fn pthread_rwlock_rdlock(rwlock: *mut pthread_rwlock_t) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn pthread_rwlock_tryrdlock(rwlock: *mut pthread_rwlock_t) -> libc::c_int {
+pub extern "C" fn pthread_rwlock_tryrdlock(rwlock: *mut pthread_rwlock_t) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn pthread_rwlock_trywrlock(rwlock: *mut pthread_rwlock_t) -> libc::c_int {
+pub extern "C" fn pthread_rwlock_trywrlock(rwlock: *mut pthread_rwlock_t) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn pthread_rwlock_unlock(rwlock: *mut pthread_rwlock_t) -> libc::c_int {
+pub extern "C" fn pthread_rwlock_unlock(rwlock: *mut pthread_rwlock_t) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn pthread_rwlock_wrlock(rwlock: *mut pthread_rwlock_t) -> libc::c_int {
+pub extern "C" fn pthread_rwlock_wrlock(rwlock: *mut pthread_rwlock_t) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn pthread_rwlockattr_destroy(rwlock: *mut pthread_rwlockattr_t) -> libc::c_int {
+pub extern "C" fn pthread_rwlockattr_destroy(rwlock: *mut pthread_rwlockattr_t) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
 pub extern "C" fn pthread_rwlockattr_getpshared(
     rwlock: *const pthread_rwlockattr_t,
-    pshared: *mut libc::c_int,
-) -> libc::c_int {
+    pshared: *mut c_int,
+) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn pthread_rwlockattr_init(rwlock: *mut pthread_rwlockattr_t) -> libc::c_int {
+pub extern "C" fn pthread_rwlockattr_init(rwlock: *mut pthread_rwlockattr_t) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
 pub extern "C" fn pthread_rwlockattr_setpshared(
     rwlock: *mut pthread_rwlockattr_t,
-    pshared: libc::c_int,
-) -> libc::c_int {
+    pshared: c_int,
+) -> c_int {
     unimplemented!();
 }
 
@@ -470,34 +483,34 @@ pub extern "C" fn pthread_self() -> pthread_t {
 }
 
 // #[no_mangle]
-pub extern "C" fn pthread_setcancelstate(state: libc::c_int, oldstate: *mut libc::c_int) -> libc::c_int {
+pub extern "C" fn pthread_setcancelstate(state: c_int, oldstate: *mut c_int) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn pthread_setcanceltype(type_: libc::c_int, oldtype: *mut libc::c_int) -> libc::c_int {
+pub extern "C" fn pthread_setcanceltype(type_: c_int, oldtype: *mut c_int) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn pthread_setconcurrency(new_level: libc::c_int) -> libc::c_int {
+pub extern "C" fn pthread_setconcurrency(new_level: c_int) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
 pub extern "C" fn pthread_setschedparam(
     thread: pthread_t,
-    policy: libc::c_int,
+    policy: c_int,
     param: *mut sched_param,
-) -> libc::c_int {
+) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
 pub extern "C" fn pthread_setspecific(
     key: pthread_key_t,
-    value: *const libc::c_void,
-) -> libc::c_int {
+    value: *const c_void,
+) -> c_int {
     unimplemented!();
 }
 
@@ -505,44 +518,3 @@ pub extern "C" fn pthread_setspecific(
 pub extern "C" fn pthread_testcancel() {
     unimplemented!();
 }
-
-#[repr(C)]
-#[derive(Debug, Copy)]
-pub struct sched_param {
-    pub _address: u8,
-}
-impl Clone for sched_param {
-    fn clone(&self) -> Self {
-        *self
-    }
-}
-#[repr(C)]
-#[derive(Debug, Copy)]
-pub struct sched_param {
-    pub _address: u8,
-}
-impl Clone for sched_param {
-    fn clone(&self) -> Self {
-        *self
-    }
-}
-#[repr(C)]
-#[derive(Debug, Copy)]
-pub struct sched_param {
-    pub _address: u8,
-}
-impl Clone for sched_param {
-    fn clone(&self) -> Self {
-        *self
-    }
-}
-#[repr(C)]
-#[derive(Debug, Copy)]
-pub struct sched_param {
-    pub _address: u8,
-}
-impl Clone for sched_param {
-    fn clone(&self) -> Self {
-        *self
-    }
-}

+ 0 - 0
src/template/cbindgen.toml → src/header/_template/cbindgen.toml


+ 0 - 4
src/template/src/lib.rs → src/header/_template/mod.rs

@@ -1,9 +1,5 @@
 //! template implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/template.h.html
 
-#![no_std]
-
-extern crate platform;
-
 use platform::types::*;
 
 /*

+ 7 - 0
src/header/aio/cbindgen.toml

@@ -0,0 +1,7 @@
+sys_includes = []
+include_guard = "_AIO_H"
+language = "C"
+style = "Tag"
+
+[enum]
+prefix_with_name = true

+ 17 - 14
src/todo/aio/lib.rs → src/header/aio/mod.rs

@@ -1,34 +1,37 @@
+use header::time::sigevent;
+use platform::types::*;
+
 pub struct aiocb {
-    pub aio_fildes: libc::c_int,
-    pub aio_lio_opcode: libc::c_int,
-    pub aio_reqprio: libc::c_int,
-    pub aio_buf: *mut libc::c_void,
+    pub aio_fildes: c_int,
+    pub aio_lio_opcode: c_int,
+    pub aio_reqprio: c_int,
+    pub aio_buf: *mut c_void,
     pub aio_nbytes: usize,
     pub aio_sigevent: sigevent,
 }
 
 // #[no_mangle]
-pub extern "C" fn aio_read(aiocbp: *mut aiocb) -> libc::c_int {
+pub extern "C" fn aio_read(aiocbp: *mut aiocb) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn aio_write(aiocbp: *mut aiocb) -> libc::c_int {
+pub extern "C" fn aio_write(aiocbp: *mut aiocb) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
 pub extern "C" fn lio_listio(
-    mode: libc::c_int,
+    mode: c_int,
     list: *const *const aiocb,
-    nent: libc::c_int,
+    nent: c_int,
     sig: *mut sigevent,
-) -> libc::c_int {
+) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn aio_error(aiocbp: *const aiocb) -> libc::c_int {
+pub extern "C" fn aio_error(aiocbp: *const aiocb) -> c_int {
     unimplemented!();
 }
 
@@ -38,20 +41,20 @@ pub extern "C" fn aio_return(aiocbp: *mut aiocb) -> usize {
 }
 
 // #[no_mangle]
-pub extern "C" fn aio_cancel(fildes: libc::c_int, aiocbp: *mut aiocb) -> libc::c_int {
+pub extern "C" fn aio_cancel(fildes: c_int, aiocbp: *mut aiocb) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
 pub extern "C" fn aio_suspend(
     list: *const *const aiocb,
-    nent: libc::c_int,
+    nent: c_int,
     timeout: *const timespec,
-) -> libc::c_int {
+) -> c_int {
     unimplemented!();
 }
 
 // #[no_mangle]
-pub extern "C" fn aio_fsync(operation: libc::c_int, aiocbp: *mut aiocb) -> libc::c_int {
+pub extern "C" fn aio_fsync(operation: c_int, aiocbp: *mut aiocb) -> c_int {
     unimplemented!();
 }

+ 1 - 1
src/arpainet/cbindgen.toml → src/header/arpa_inet/cbindgen.toml

@@ -1,5 +1,5 @@
 sys_includes = ["stddef.h", "sys/socket.h", "netinet/in.h"]
-include_guard = "_ARPAINET_H"
+include_guard = "_ARPA_INET_H"
 language = "C"
 style = "Tag"
 

+ 14 - 23
src/arpainet/src/lib.rs → src/header/arpa_inet/mod.rs

@@ -1,20 +1,11 @@
-//! arpainet implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/arpainet.h.html
-
-#![no_std]
-#![feature(alloc)]
-
-#[macro_use]
-extern crate alloc;
-
-extern crate errno;
-extern crate netinet;
-extern crate platform;
-extern crate sys_socket;
+//! arpa/inet implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/arpainet.h.html
 
 use core::str::FromStr;
-use core::{mem, ptr, slice, str};
-use errno::*;
-use netinet::in_h::in_addr;
+use core::{ptr, slice, str};
+
+use header::errno::*;
+use header::netinet_in::in_addr;
+use platform;
 use platform::c_str;
 use platform::types::*;
 
@@ -38,8 +29,6 @@ pub extern "C" fn ntohs(netshort: u16) -> u16 {
     u16::from_be(netshort)
 }
 
-static mut NTOA_ADDR: [c_char; 16] = [0; 16];
-
 #[no_mangle]
 pub unsafe extern "C" fn inet_aton(cp: *const c_char, inp: *mut in_addr) -> c_int {
     // TODO: octal/hex
@@ -48,6 +37,8 @@ pub unsafe extern "C" fn inet_aton(cp: *const c_char, inp: *mut in_addr) -> c_in
 
 #[no_mangle]
 pub unsafe extern "C" fn inet_ntoa(addr: in_addr) -> *const c_char {
+    static mut NTOA_ADDR: [c_char; 16] = [0; 16];
+
     inet_ntop(
         AF_INET,
         &addr as *const in_addr as *const c_void,
@@ -62,7 +53,7 @@ pub unsafe extern "C" fn inet_pton(domain: c_int, src: *const c_char, dest: *mut
         platform::errno = EAFNOSUPPORT;
         -1
     } else {
-        let mut s_addr = slice::from_raw_parts_mut(
+        let s_addr = slice::from_raw_parts_mut(
             &mut (*(dest as *mut in_addr)).s_addr as *mut _ as *mut u8,
             4,
         );
@@ -106,27 +97,27 @@ pub unsafe extern "C" fn inet_ntop(
     }
 }
 
-#[no_mangle]
+//#[no_mangle]
 pub extern "C" fn inet_addr(cp: *const c_char) -> in_addr_t {
     unimplemented!();
 }
 
-#[no_mangle]
+//#[no_mangle]
 pub extern "C" fn inet_lnaof(_in: in_addr) -> in_addr_t {
     unimplemented!();
 }
 
-#[no_mangle]
+//#[no_mangle]
 pub extern "C" fn inet_makeaddr(net: in_addr_t, lna: in_addr_t) -> in_addr {
     unimplemented!();
 }
 
-#[no_mangle]
+//#[no_mangle]
 pub extern "C" fn inet_netof(_in: in_addr) -> in_addr_t {
     unimplemented!();
 }
 
-#[no_mangle]
+//#[no_mangle]
 pub extern "C" fn inet_network(cp: *const c_char) -> in_addr_t {
     unimplemented!();
 }

+ 0 - 0
src/ctype/cbindgen.toml → src/header/ctype/cbindgen.toml


+ 0 - 4
src/ctype/src/lib.rs → src/header/ctype/mod.rs

@@ -1,9 +1,5 @@
 //! ctype implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/ctype.h.html
 
-#![no_std]
-
-extern crate platform;
-
 use platform::types::*;
 
 #[no_mangle]

+ 0 - 0
src/dirent/cbindgen.toml → src/header/dirent/cbindgen.toml


+ 9 - 13
src/dirent/src/lib.rs → src/header/dirent/mod.rs

@@ -1,18 +1,13 @@
 //! dirent implementation following http://pubs.opengroup.org/onlinepubs/009695399/basedefs/dirent.h.html
 
-#![no_std]
-#![feature(alloc)]
-
-extern crate alloc;
-extern crate errno;
-extern crate fcntl;
-extern crate platform;
-extern crate stdio;
-extern crate unistd;
-
 use alloc::boxed::Box;
 use core::{mem, ptr};
+
+use c_str::CStr;
+use header::{errno, fcntl, unistd};
+use platform;
 use platform::types::*;
+use platform::{Pal, Sys};
 
 const DIR_BUF_SIZE: usize = mem::size_of::<dirent>() * 3;
 
@@ -41,7 +36,8 @@ pub struct dirent {
 
 #[no_mangle]
 pub extern "C" fn opendir(path: *const c_char) -> *mut DIR {
-    let fd = platform::open(
+    let path = unsafe { CStr::from_ptr(path) };
+    let fd = Sys::open(
         path,
         fcntl::O_RDONLY | fcntl::O_DIRECTORY | fcntl::O_CLOEXEC,
         0,
@@ -62,7 +58,7 @@ pub extern "C" fn opendir(path: *const c_char) -> *mut DIR {
 
 #[no_mangle]
 pub unsafe extern "C" fn closedir(dir: *mut DIR) -> c_int {
-    let ret = platform::close((*dir).fd);
+    let ret = Sys::close((*dir).fd);
     Box::from_raw(dir);
     ret
 }
@@ -70,7 +66,7 @@ pub unsafe extern "C" fn closedir(dir: *mut DIR) -> c_int {
 #[no_mangle]
 pub unsafe extern "C" fn readdir(dir: *mut DIR) -> *mut dirent {
     if (*dir).index >= (*dir).len {
-        let read = platform::getdents(
+        let read = Sys::getdents(
             (*dir).fd,
             (*dir).buf.as_mut_ptr() as *mut platform::types::dirent,
             (*dir).buf.len(),

+ 0 - 0
src/errno/cbindgen.toml → src/header/errno/cbindgen.toml


+ 1 - 4
src/errno/src/lib.rs → src/header/errno/mod.rs

@@ -1,9 +1,6 @@
 //! errno implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/errno.h.html
 
-#![no_std]
-
-extern crate platform;
-
+use platform;
 use platform::types::*;
 
 #[no_mangle]

+ 0 - 0
src/fcntl/cbindgen.toml → src/header/fcntl/cbindgen.toml


+ 15 - 0
src/header/fcntl/linux.rs

@@ -0,0 +1,15 @@
+use platform::types::*;
+
+pub const O_RDONLY: c_int = 0x0000;
+pub const O_WRONLY: c_int = 0x0001;
+pub const O_RDWR: c_int = 0x0002;
+pub const O_CREAT: c_int = 0x0040;
+pub const O_EXCL: c_int = 0x0080;
+pub const O_TRUNC: c_int = 0x0200;
+pub const O_APPEND: c_int = 0x0400;
+pub const O_NONBLOCK: c_int = 0x0800;
+pub const O_DIRECTORY: c_int = 0x1_0000;
+pub const O_NOFOLLOW: c_int = 0x2_0000;
+pub const O_CLOEXEC: c_int = 0x8_0000;
+pub const O_PATH: c_int = 0x20_0000;
+pub const O_ACCMODE: c_int = O_RDONLY | O_WRONLY | O_RDWR;

+ 6 - 14
src/fcntl/src/lib.rs → src/header/fcntl/mod.rs

@@ -1,12 +1,10 @@
 //! fcntl implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/fcntl.h.html
 
-#![no_std]
-
-extern crate platform;
-
+use c_str::CStr;
 use platform::types::*;
+use platform::{Pal, Sys};
 
-pub use sys::*;
+pub use self::sys::*;
 
 #[cfg(target_os = "linux")]
 #[path = "linux.rs"]
@@ -38,17 +36,11 @@ pub extern "C" fn creat(path: *const c_char, mode: mode_t) -> c_int {
 
 #[no_mangle]
 pub extern "C" fn sys_fcntl(fildes: c_int, cmd: c_int, arg: c_int) -> c_int {
-    platform::fcntl(fildes, cmd, arg)
+    Sys::fcntl(fildes, cmd, arg)
 }
 
 #[no_mangle]
 pub extern "C" fn sys_open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int {
-    platform::open(path, oflag, mode)
-}
-
-/*
-#[no_mangle]
-pub extern "C" fn func(args) -> c_int {
-    unimplemented!();
+    let path = unsafe { CStr::from_ptr(path) };
+    Sys::open(path, oflag, mode)
 }
-*/

+ 1 - 1
src/fcntl/src/redox.rs → src/header/fcntl/redox.rs

@@ -14,7 +14,7 @@ pub const O_CREAT: c_int = 0x0200_0000;
 pub const O_TRUNC: c_int = 0x0400_0000;
 pub const O_EXCL: c_int = 0x0800_0000;
 pub const O_DIRECTORY: c_int = 0x1000_0000;
-pub const O_STAT: c_int = 0x2000_0000;
+pub const O_PATH: c_int = 0x2000_0000;
 pub const O_SYMLINK: c_int = 0x4000_0000;
 pub const O_NOFOLLOW: c_int = 0x8000_0000;
 pub const O_ACCMODE: c_int = O_RDONLY | O_WRONLY | O_RDWR;

+ 0 - 0
src/fenv/cbindgen.toml → src/header/fenv/cbindgen.toml


+ 0 - 4
src/fenv/src/lib.rs → src/header/fenv/mod.rs

@@ -1,10 +1,6 @@
 //! fenv.h implementation for Redox, following
 //! http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/fenv.h.html
 
-#![no_std]
-
-extern crate platform;
-
 use platform::types::*;
 
 pub const FE_ALL_EXCEPT: c_int = 0;

+ 0 - 0
src/float/cbindgen.toml → src/header/float/cbindgen.toml


+ 1 - 6
src/float/src/lib.rs → src/header/float/mod.rs

@@ -1,12 +1,7 @@
 //! float.h implementation for Redox, following
 //! http://pubs.opengroup.org/onlinepubs/7908799/xsh/float.h.html
 
-#![no_std]
-
-extern crate fenv;
-extern crate platform;
-
-use fenv::{fegetround, FE_TONEAREST};
+use header::fenv::{fegetround, FE_TONEAREST};
 use platform::types::*;
 
 pub const FLT_RADIX: c_int = 2;

+ 0 - 0
src/fnmatch/cbindgen.toml → src/header/fnmatch/cbindgen.toml


+ 22 - 20
src/fnmatch/src/lib.rs → src/header/fnmatch/mod.rs

@@ -1,18 +1,14 @@
 //! fnmatch implementation
-#![no_std]
-#![feature(alloc)]
-
-extern crate alloc;
-extern crate platform;
 
 use alloc::vec::Vec;
+
 use platform::types::*;
 
 pub const FNM_NOMATCH: c_int = 1;
 
 pub const FNM_NOESCAPE: c_int = 1;
 pub const FNM_PATHNAME: c_int = 2;
-pub const FNM_PERIOD:   c_int = 4;
+pub const FNM_PERIOD: c_int = 4;
 pub const FNM_CASEFOLD: c_int = 8;
 
 #[derive(Debug)]
@@ -43,7 +39,7 @@ unsafe fn next_token(pattern: &mut *const c_char, flags: c_int) -> Option<Token>
             }
             *pattern = pattern.offset(1);
             Token::Char(c)
-        },
+        }
         b'?' => Token::Any,
         b'*' => Token::Wildcard,
         b'[' => {
@@ -51,7 +47,9 @@ unsafe fn next_token(pattern: &mut *const c_char, flags: c_int) -> Option<Token>
             let invert = if **pattern as u8 == b'!' {
                 *pattern = pattern.offset(1);
                 true
-            } else { false };
+            } else {
+                false
+            };
 
             loop {
                 let mut c = **pattern as u8;
@@ -68,8 +66,8 @@ unsafe fn next_token(pattern: &mut *const c_char, flags: c_int) -> Option<Token>
                             // Trailing backslash. Maybe error?
                             break;
                         }
-                    },
-                    _ => ()
+                    }
+                    _ => (),
                 }
                 if matches.len() >= 2 && matches[matches.len() - 1] == b'-' {
                     let len = matches.len();
@@ -85,13 +83,17 @@ unsafe fn next_token(pattern: &mut *const c_char, flags: c_int) -> Option<Token>
             // Otherwise, there was no closing ]. Maybe error?
 
             Token::Match(invert, matches)
-        },
-        c => Token::Char(c)
+        }
+        c => Token::Char(c),
     })
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn fnmatch(mut pattern: *const c_char, mut input: *const c_char, flags: c_int) -> c_int {
+pub unsafe extern "C" fn fnmatch(
+    mut pattern: *const c_char,
+    mut input: *const c_char,
+    flags: c_int,
+) -> c_int {
     let pathname = flags & FNM_PATHNAME == FNM_PATHNAME;
     let casefold = flags & FNM_CASEFOLD == FNM_CASEFOLD;
 
@@ -113,7 +115,7 @@ pub unsafe extern "C" fn fnmatch(mut pattern: *const c_char, mut input: *const c
                     return FNM_NOMATCH;
                 }
                 input = input.offset(1);
-            },
+            }
             Some(Token::Char(c)) => {
                 let mut a = *input as u8;
                 if casefold && a >= b'a' && a <= b'z' {
@@ -130,14 +132,15 @@ pub unsafe extern "C" fn fnmatch(mut pattern: *const c_char, mut input: *const c
                     leading = true;
                 }
                 input = input.offset(1);
-            },
+            }
             Some(Token::Match(invert, matches)) => {
-                if (pathname && *input as u8 == b'/') || matches.contains(&(*input as u8)) == invert {
+                if (pathname && *input as u8 == b'/') || matches.contains(&(*input as u8)) == invert
+                {
                     // Found it, but it's inverted! Or vise versa.
                     return FNM_NOMATCH;
                 }
                 input = input.offset(1);
-            },
+            }
             Some(Token::Wildcard) => {
                 loop {
                     let c = *input as u8;
@@ -158,9 +161,8 @@ pub unsafe extern "C" fn fnmatch(mut pattern: *const c_char, mut input: *const c
                         return FNM_NOMATCH;
                     }
                 }
-                unreachable!("nothing should be able to break out of the loop");
-            },
-            None => return FNM_NOMATCH // Pattern ended but there's still some input
+            }
+            None => return FNM_NOMATCH, // Pattern ended but there's still some input
         }
     }
 }

+ 0 - 0
src/grp/cbindgen.toml → src/header/grp/cbindgen.toml


+ 0 - 4
src/grp/src/lib.rs → src/header/grp/mod.rs

@@ -1,9 +1,5 @@
 //! grp implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/grp.h.html
 
-#![no_std]
-
-extern crate platform;
-
 use platform::types::*;
 
 #[repr(C)]

+ 0 - 0
src/inttypes/cbindgen.toml → src/header/inttypes/cbindgen.toml


+ 4 - 11
src/inttypes/src/lib.rs → src/header/inttypes/mod.rs

@@ -1,12 +1,7 @@
-#![no_std]
-
-#[macro_use]
-extern crate stdlib;
-extern crate ctype;
-extern crate errno;
-extern crate platform;
-
-use errno::*;
+use header::ctype;
+use header::errno::*;
+use header::stdlib::*;
+use platform;
 use platform::types::*;
 
 #[no_mangle]
@@ -35,7 +30,6 @@ pub unsafe extern "C" fn strtoimax(
     endptr: *mut *mut c_char,
     base: c_int,
 ) -> intmax_t {
-    use stdlib::*;
     strto_impl!(
         intmax_t,
         false,
@@ -53,7 +47,6 @@ pub unsafe extern "C" fn strtoumax(
     endptr: *mut *mut c_char,
     base: c_int,
 ) -> uintmax_t {
-    use stdlib::*;
     strto_impl!(
         uintmax_t,
         false,

+ 0 - 0
src/locale/cbindgen.toml → src/header/locale/cbindgen.toml


+ 1 - 5
src/locale/src/lib.rs → src/header/locale/mod.rs

@@ -1,11 +1,7 @@
 //! locale implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/locale.h.html
 
-#![no_std]
-#![feature(alloc)]
-
-extern crate platform;
-
 use core::ptr;
+
 use platform::types::*;
 
 const EMPTY_PTR: *const c_char = "\0" as *const _ as *const c_char;

+ 41 - 0
src/header/mod.rs

@@ -0,0 +1,41 @@
+pub mod aio;
+pub mod arpa_inet;
+pub mod ctype;
+pub mod dirent;
+pub mod errno;
+pub mod fcntl;
+pub mod fenv;
+pub mod float;
+pub mod fnmatch;
+pub mod grp;
+pub mod inttypes;
+pub mod locale;
+pub mod netinet_in;
+//pub mod pthread;
+pub mod pwd;
+pub mod semaphore;
+pub mod setjmp;
+pub mod sgtty;
+pub mod signal;
+pub mod stdio;
+pub mod stdlib;
+pub mod string;
+pub mod strings;
+pub mod sys_file;
+pub mod sys_ioctl;
+pub mod sys_mman;
+pub mod sys_resource;
+pub mod sys_select;
+pub mod sys_socket;
+pub mod sys_stat;
+pub mod sys_time;
+pub mod sys_times;
+pub mod sys_un;
+pub mod sys_utsname;
+pub mod sys_wait;
+pub mod termios;
+pub mod time;
+pub mod unistd;
+pub mod utime;
+pub mod wchar;
+pub mod wctype;

+ 0 - 0
src/netinet/Cargo.toml → src/header/netinet_in/Cargo.toml


+ 0 - 0
src/netinet/in/cbindgen.toml → src/header/netinet_in/cbindgen.toml


+ 5 - 10
src/netinet/in/src/lib.rs → src/header/netinet_in/mod.rs

@@ -1,12 +1,7 @@
-#![no_std]
-
 #![allow(non_camel_case_types)]
 
-extern crate platform;
-extern crate sys_socket;
-
+use header::sys_socket::sa_family_t;
 use platform::types::*;
-use sys_socket::{sa_family_t, sockaddr};
 
 pub type in_addr_t = u32;
 pub type in_port_t = u16;
@@ -14,19 +9,19 @@ pub type in_port_t = u16;
 #[repr(C)]
 #[derive(Debug, Clone, Copy)]
 pub struct in_addr {
-    pub s_addr: in_addr_t
+    pub s_addr: in_addr_t,
 }
 
 #[repr(C)]
 pub struct in6_addr {
-    pub s6_addr: [u8; 16]
+    pub s6_addr: [u8; 16],
 }
 
 #[repr(C)]
 pub struct sockaddr_in {
     pub sin_family: sa_family_t,
     pub sin_port: in_port_t,
-    pub sin_addr: in_addr
+    pub sin_addr: in_addr,
 }
 
 #[repr(C)]
@@ -35,7 +30,7 @@ pub struct sockaddr_in6 {
     pub sin6_port: in_port_t,
     pub sin6_flowinfo: u32,
     pub sin6_addr: in6_addr,
-    pub sin6_scope_id: u32
+    pub sin6_scope_id: u32,
 }
 
 #[repr(C)]

+ 0 - 0
src/pwd/cbindgen.toml → src/header/pwd/cbindgen.toml


+ 7 - 10
src/pwd/src/lib.rs → src/header/pwd/mod.rs

@@ -1,17 +1,14 @@
 //! pwd implementation for relibc
 
-#![no_std]
-#![feature(alloc)]
-
-extern crate alloc;
-extern crate errno;
-extern crate fcntl;
-extern crate platform;
-
 use alloc::vec::Vec;
 use core::ptr;
+
+use c_str::CStr;
+use header::{errno, fcntl};
+use platform;
 use platform::types::*;
 use platform::RawFile;
+use platform::{Pal, Sys};
 
 #[repr(C)]
 pub struct passwd {
@@ -51,7 +48,7 @@ where
     F: FnMut(&[&[u8]]) -> bool,
 {
     let file = match RawFile::open(
-        "/etc/passwd\0".as_ptr() as *const c_char,
+        unsafe { CStr::from_bytes_with_nul_unchecked(b"/etc/passwd\0") },
         fcntl::O_RDONLY,
         0,
     ) {
@@ -90,7 +87,7 @@ where
                 buf.set_len(capacity);
             }
 
-            let read = platform::read(*file, &mut buf[len..]);
+            let read = Sys::read(*file, &mut buf[len..]);
 
             unsafe {
                 buf.set_len(len + read as usize);

+ 0 - 0
src/semaphore/cbindgen.toml → src/header/semaphore/cbindgen.toml


+ 0 - 4
src/semaphore/src/lib.rs → src/header/semaphore/mod.rs

@@ -1,7 +1,3 @@
-#![no_std]
-
-extern crate platform;
-
 use platform::types::*;
 
 #[repr(C)]

+ 0 - 0
src/setjmp/src/impl/README.md → src/header/setjmp/impl/README.md


+ 0 - 0
src/setjmp/src/impl/aarch64/longjmp.s → src/header/setjmp/impl/aarch64/longjmp.s


+ 0 - 0
src/setjmp/src/impl/aarch64/setjmp.s → src/header/setjmp/impl/aarch64/setjmp.s


+ 0 - 0
src/setjmp/src/impl/arm/longjmp.s → src/header/setjmp/impl/arm/longjmp.s


+ 0 - 0
src/setjmp/src/impl/arm/setjmp.s → src/header/setjmp/impl/arm/setjmp.s


+ 0 - 0
src/setjmp/src/impl/i386/longjmp.s → src/header/setjmp/impl/i386/longjmp.s


+ 0 - 0
src/setjmp/src/impl/i386/setjmp.s → src/header/setjmp/impl/i386/setjmp.s


+ 0 - 0
src/setjmp/src/impl/m68k/longjmp.s → src/header/setjmp/impl/m68k/longjmp.s


+ 0 - 0
src/setjmp/src/impl/m68k/setjmp.s → src/header/setjmp/impl/m68k/setjmp.s


+ 0 - 0
src/setjmp/src/impl/microblaze/longjmp.s → src/header/setjmp/impl/microblaze/longjmp.s


+ 0 - 0
src/setjmp/src/impl/microblaze/setjmp.s → src/header/setjmp/impl/microblaze/setjmp.s


+ 0 - 0
src/setjmp/src/impl/mips/longjmp.S → src/header/setjmp/impl/mips/longjmp.S


+ 0 - 0
src/setjmp/src/impl/mips/setjmp.S → src/header/setjmp/impl/mips/setjmp.S


+ 0 - 0
src/setjmp/src/impl/mips64/longjmp.S → src/header/setjmp/impl/mips64/longjmp.S


Some files were not shown because too many files changed in this diff