[lib] fix #49 by using correctly mkstemp and fdopen