Commit 401a3361ea

MovingtoMars <liam@bumblebee.net.nz>
2016-01-28 04:01:52
malloc fails on mmap error code properly
1 parent 9c50203
Changed files (1)
std/mem.zig
@@ -10,23 +10,7 @@ pub fn malloc(bytes: isize) -> ?&u8 {
 
     const result = mmap(isize(0), 4096, MMAP_PROT_READ|MMAP_PROT_WRITE, MMAP_MAP_ANON|MMAP_MAP_SHARED, -1, 0);
 
-    const failed: bool = switch (-result) {
-        0          => true,
-        -1         => true,
-        EINVAL     => true,
-        EACCES     => true,
-        EAGAIN     => true,
-        EBADF      => true,
-        EMFILE     => true,
-        ENODEV     => true,
-        ENOMEM     => true,
-        EOPNOTSUPP => true,
-        ENXIO      => true,
-        EOVERFLOW  => true,
-        else       => false,
-    };
-
-    if (failed) {
+    if (-4096 < result && result <= 0) {
         null
     } else {
         (&u8)(result)