home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.bin / SourceCode / libcs / filecopy.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-11  |  2.9 KB  |  73 lines

  1. /*
  2.  * Copyright (c) 1990 Carnegie Mellon University
  3.  * All Rights Reserved.
  4.  * 
  5.  * Permission to use, copy, modify and distribute this software and its
  6.  * documentation is hereby granted, provided that both the copyright
  7.  * notice and this permission notice appear in all copies of the
  8.  * software, derivative works or modified versions, and any portions
  9.  * thereof, and that both notices appear in supporting documentation.
  10.  *
  11.  * THE SOFTWARE IS PROVIDED "AS IS" AND CARNEGIE MELLON UNIVERSITY
  12.  * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  13.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.  IN NO EVENT
  14.  * SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE FOR ANY SPECIAL, DIRECT,
  15.  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  16.  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
  17.  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  18.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  19.  *
  20.  * Users of this software agree to return to Carnegie Mellon any
  21.  * improvements or extensions that they make and grant Carnegie the
  22.  * rights to redistribute these changes.
  23.  *
  24.  * Export of this software is permitted only after complying with the
  25.  * regulations of the U.S. Deptartment of Commerce relating to the
  26.  * Export of Technical Data.
  27.  */
  28. /*  filecopy  --  copy a file from here to there
  29.  *
  30.  *  Usage:  i = filecopy (here,there);
  31.  *    int i, here, there;
  32.  *
  33.  *  Filecopy performs a fast copy of the file "here" to the
  34.  *  file "there".  Here and there are both file descriptors of
  35.  *  open files; here is open for input, and there for output.
  36.  *  Filecopy returns 0 if all is OK; -1 on error.
  37.  *
  38.  *  I have performed some tests for possible improvements to filecopy.
  39.  *  Using a buffer size of 10240 provides about a 1.5 times speedup
  40.  *  over 512 for a file of about 200,000 bytes.  Of course, other
  41.  *  buffer sized should also work; this is a rather arbitrary choice.
  42.  *  I have also tried inserting special startup code to attempt
  43.  *  to align either the input or the output file to lie on a
  44.  *  physical (512-byte) block boundary prior to the big loop,
  45.  *  but this presents only a small (about 5% speedup, so I've
  46.  *  canned that code.  The simple thing seems to be good enough.
  47.  *
  48.  *  HISTORY
  49.  * $Log:    filecopy.c,v $
  50.  * Revision 1.2  90/12/11  17:52:57  mja
  51.  *     Add copyright/disclaimer for distribution.
  52.  * 
  53.  * 20-Nov-79  Steven Shafer (sas) at Carnegie-Mellon University
  54.  *    Rewritten for VAX; same as "filcopy" on PDP-11.  Bigger buffer
  55.  *    size (20 physical blocks) seems to be a big win; aligning things
  56.  *    on block boundaries seems to be a negligible improvement at
  57.  *    considerable cost in complexity.
  58.  *
  59.  */
  60.  
  61. #define BUFFERSIZE 10240
  62.  
  63. int filecopy (here,there)
  64. int here,there;
  65. {
  66.     register int kount;
  67.     char buffer[BUFFERSIZE];
  68.     kount = 0;
  69.     while (kount == 0 && (kount=read(here,buffer,BUFFERSIZE)) > 0)
  70.         kount -= write (there,buffer,kount);
  71.     return (kount ? -1 : 0);
  72. }
  73.