Fix error checking in MemoryFile.

mmap returns MAP_FAILED on failures, not 0 (NULL).
Also, convert some C style casts to C++ since they
make intent clearer.

Credit: Narayan Kamath

Backported from VanirAOSP, kk44 branch
http://vaniraosp.goo.im/#/c/9737/2

Change-Id: Iebab6c0b78f2342f0aa3857eec0d33dd3d0e94ba