close functions, support for envp (can be NULL for no change)