utils: add patch_fd() and patch_stdio() helpers