Changeset 3fb0fec in mainline for uspace/app/bdsh/cmds/modules/cp/cp.c


Ignore:
Timestamp:
2011-07-26T18:29:44Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7eb0fed8
Parents:
efcebe1 (diff), aa865ee (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/modules/cp/cp.c

    refcebe1 r3fb0fec  
    7171        size_t blen, int vb)
    7272{
    73         int fd1, fd2, bytes = 0;
    74         off64_t total = 0;
     73        int fd1, fd2, bytes;
     74        off64_t total;
    7575        int64_t copied = 0;
    7676        char *buff = NULL;
     
    104104        }
    105105
    106         for (;;) {
    107                 ssize_t res;
    108                 size_t written = 0;
    109 
    110                 bytes = read(fd1, buff, blen);
    111                 if (bytes <= 0)
     106        while ((bytes = read_all(fd1, buff, blen)) > 0) {
     107                if ((bytes = write_all(fd2, buff, bytes)) < 0)
    112108                        break;
    113109                copied += bytes;
    114                 res = bytes;
    115                 do {
    116                         /*
    117                          * Theoretically, it may not be enough to call write()
    118                          * only once. Also the previous read() may have
    119                          * returned less data than requested.
    120                          */
    121                         bytes = write(fd2, buff + written, res);
    122                         if (bytes < 0)
    123                                 goto err;
    124                         written += bytes;
    125                         res -= bytes;
    126                 } while (res > 0);
    127 
    128                 /* TODO: re-insert assert() once this is stand alone,
    129                  * removed as abort() exits the entire shell
    130                  */
    131                 if (res != 0) {
    132                         printf("\n%zd more bytes than actually exist were copied\n", res);
    133                         goto err;
    134                 }
    135110        }
    136111
    137112        if (bytes < 0) {
    138 err:
    139113                printf("\nError copying %s, (%d)\n", src, bytes);
    140114                copied = bytes;
Note: See TracChangeset for help on using the changeset viewer.