1 /* $NetBSD: filecopy.c,v 1.4 2002/07/10 20:19:39 wiz Exp $ */
4 * Copyright (c) 1991 Carnegie Mellon University
7 * Permission to use, copy, modify and distribute this software and its
8 * documentation is hereby granted, provided that both the copyright
9 * notice and this permission notice appear in all copies of the
10 * software, derivative works or modified versions, and any portions
11 * thereof, and that both notices appear in supporting documentation.
13 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
14 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
15 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17 * Carnegie Mellon requests users of this software to return to
19 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
20 * School of Computer Science
21 * Carnegie Mellon University
22 * Pittsburgh PA 15213-3890
24 * any improvements or extensions that they make and grant Carnegie the rights
25 * to redistribute these changes.
27 /* filecopy -- copy a file from here to there
29 * Usage: i = filecopy (here,there);
32 * Filecopy performs a fast copy of the file "here" to the
33 * file "there". Here and there are both file descriptors of
34 * open files; here is open for input, and there for output.
35 * Filecopy returns 0 if all is OK; -1 on error.
37 * I have performed some tests for possible improvements to filecopy.
38 * Using a buffer size of 10240 provides about a 1.5 times speedup
39 * over 512 for a file of about 200,000 bytes. Of course, other
40 * buffer sized should also work; this is a rather arbitrary choice.
41 * I have also tried inserting special startup code to attempt
42 * to align either the input or the output file to lie on a
43 * physical (512-byte) block boundary prior to the big loop,
44 * but this presents only a small (about 5% speedup, so I've
45 * canned that code. The simple thing seems to be good enough.
48 * 20-Nov-79 Steven Shafer (sas) at Carnegie-Mellon University
49 * Rewritten for VAX; same as "filcopy" on PDP-11. Bigger buffer
50 * size (20 physical blocks) seems to be a big win; aligning things
51 * on block boundaries seems to be a negligible improvement at
52 * considerable cost in complexity.
56 #define BUFFERSIZE 10240
58 #include "supextern.h"
61 filecopy(int here
, int there
)
64 char buffer
[BUFFERSIZE
];
66 while (kount
== 0 && (kount
= read(here
, buffer
, BUFFERSIZE
)) > 0)
67 kount
-= write(there
, buffer
, (size_t)kount
);
68 return (kount
? -1 : 0);