| 1 | /* |
| 2 | * Copyright (c) 1988 Regents of the University of California. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms are permitted |
| 6 | * provided that this notice is preserved and that due credit is given |
| 7 | * to the University of California at Berkeley. The name of the University |
| 8 | * may not be used to endorse or promote products derived from this |
| 9 | * software without specific prior written permission. This software |
| 10 | * is provided ``as is'' without express or implied warranty. |
| 11 | * |
| 12 | * @(#)docopy.c 7.1 (Berkeley) %G% |
| 13 | */ |
| 14 | #define SIZE 10240 |
| 15 | |
| 16 | docopy(from, to, nrecs) |
| 17 | register int from, to, nrecs; |
| 18 | { |
| 19 | register int record, rcc, wcc; |
| 20 | char buf[SIZE]; |
| 21 | |
| 22 | for (record = 0;;) { |
| 23 | if (!(rcc = read(from, buffer, SIZE))) |
| 24 | break; |
| 25 | if (rcc < 0) { |
| 26 | printf("Record %d: read error, errno=%d\n", |
| 27 | record, errno); |
| 28 | break; |
| 29 | } |
| 30 | if (rcc < SIZE) |
| 31 | printf("Record %d: read short; expected %d, got %d\n", |
| 32 | record, SIZE, rcc); |
| 33 | #ifdef vax |
| 34 | /* For bug in ht driver. */ |
| 35 | if (rcc > SIZE) |
| 36 | rcc = SIZE; |
| 37 | #endif |
| 38 | if ((wcc = write(to, buffer, rcc)) < 0) { |
| 39 | printf("Record %d: write error: errno=%d\n", |
| 40 | record, errno); |
| 41 | break; |
| 42 | } |
| 43 | if (wcc < rcc) { |
| 44 | printf("Record %d: write short; expected %d, got %d\n", |
| 45 | record, rcc, wcc); |
| 46 | break; |
| 47 | } |
| 48 | if (nrecs > 0 && ++record == nrecs) |
| 49 | break; |
| 50 | } |
| 51 | printf("copy completed: %d records copied\n", record); |
| 52 | } |