copy.c: make copy_fd preserve meaningful errno

Update copy_fd to return a meaningful errno on failure and also
preserve the existing errno variable.

Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Merge branch 'rb/small-pieces-first' into pu

* rb/small-pieces-first:
  copy.c: make copy_fd preserve meaningful errno