Rewrite buildenv in c to avoid shell interference