malloc fails on mmap error code properly
parent
9c502030a1
commit
401a3361ea
18
std/mem.zig
18
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)
|
||||
|
|
Loading…
Reference in New Issue