STYLE fixes.
leverage fmemopen

let's make use of decent and recent POSIX features.
Simplify code and drops redundancy.