bldenv: move redirect code into redirect.c