malloc fails on mmap error code properly

master
MovingtoMars 2016-01-28 16:01:52 +13:00
parent 9c502030a1
commit 401a3361ea
1 changed files with 1 additions and 17 deletions

View File

@ -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)