X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=libbb%2Fcopyfd.c;h=22d8c3996831510739facc567275f37ed89693fc;hb=09adaca37d6bd67745c1c81c598ba25006f990b4;hp=253a8cf6e0d7e58b5147d8aff4ba9137d0c9f466;hpb=55f9872616f0c42f3fb712cfb7f9d0bb52c8afcb;p=oweals%2Fbusybox.git diff --git a/libbb/copyfd.c b/libbb/copyfd.c index 253a8cf6e..22d8c3996 100644 --- a/libbb/copyfd.c +++ b/libbb/copyfd.c @@ -2,7 +2,7 @@ /* * Utility routines. * - * Copyright (C) 1999-2001 Erik Andersen + * Copyright (C) 1999,2000,2001 by Erik Andersen * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,36 +25,28 @@ #include "libbb.h" -extern size_t copyfd(int fd1, int fd2) +extern int copyfd(int fd1, int fd2) { - char buf[32768], *writebuf; - int status = TRUE; - size_t totalread = 0, bytesread, byteswritten; + char buf[8192]; + ssize_t nread, nwrote; - while(status) { - bytesread = read(fd1, &buf, sizeof(buf)); - if(bytesread == -1) { - error_msg("read: %s", strerror(errno)); - status = FALSE; + while (1) { + nread = safe_read(fd1, buf, sizeof(buf)); + if (nread == 0) break; + if (nread == -1) { + perror_msg("read"); + return -1; } - byteswritten = 0; - writebuf = buf; - while(bytesread) { - byteswritten = write( fd2, &writebuf, bytesread ); - if(byteswritten == -1) { - error_msg("write: %s", strerror(errno)); - status = FALSE; - break; - } - bytesread -= byteswritten; - writebuf += byteswritten; + + nwrote = full_write(fd2, buf, nread); + if (nwrote == -1) { + perror_msg("write"); + return -1; } } - if ( status == TRUE ) - return totalread; - else - return -1; + + return 0; } /* END CODE */