Move copy_stream function to misc.c.