How can I detect if malloc fails in swift?
The end goal is to simply allocate the required amount of space, and if ios can not allocate it, report this elegantly to the user (instead of being terminated).
When I try the code below, the pointer is never nil and errno is always 0.
let pointer : UnsafeMutableRawPointer? = malloc(fileSize)
print("errno = \(errno)")
if (pointer == nil) {
print("Malloc failed")
}