home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume11 / zoo / part01 / getfile.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-08-16  |  1.9 KB  |  71 lines

  1. #ifndef LINT
  2. static char sccsid[]="@(#) getfile.c 1.2 87/05/03 16:00:59";
  3. #endif /* LINT */
  4.  
  5. /*
  6. Copyright (C) 1986, 1987 Rahul Dhesi -- All rights reserved
  7. */
  8.  
  9. #include "options.h"
  10. /* 
  11. This function copies n characters from the source file to the destination
  12.  
  13. Input:   output_han:    handle of destination file.
  14.          input_han:     handle of source file.
  15.          count:         count of characters to copy.
  16.          docrc:         0 if crc not wanted
  17.  
  18. If count is -1, copying is done until eof is encountered.
  19.  
  20. The source file is transferred to the current file pointer position in the
  21. destination file, using the handles provided.  Function return value is 0 
  22. if no error, 2 if write error, and 3 if read error.  
  23.  
  24. Note, however, that if the output handle is -2, it is taken to be the
  25. null device and no output actually occurs.  
  26.  
  27. If docrc is not 0, the global variable crccode is updated via addbfcrc().
  28. This is done even if the output is to the null device.
  29. */
  30.  
  31. #include <stdio.h>
  32. #include "various.h"
  33. #include "zoofns.h"
  34. #include "zoomem.h"
  35.  
  36. int getfile(input_han, output_han, count, docrc)
  37. int input_han, output_han;
  38. long count;
  39. int docrc;
  40. {
  41.    register int how_much;
  42.  
  43.    if (count == -1) {
  44.       while ((how_much = read (input_han, out_buf_adr, MEM_BLOCK_SIZE)) > 0) {
  45.          if (how_much == -1 || 
  46.                write (output_han, out_buf_adr, how_much) != how_much)
  47.             return (2);
  48.          if (docrc)
  49.             addbfcrc (out_buf_adr,how_much);
  50.       }
  51.       return (0);
  52.    }
  53.  
  54.    while (count > 0) {
  55.       if (count > MEM_BLOCK_SIZE)
  56.          how_much = MEM_BLOCK_SIZE;
  57.       else
  58.          how_much = count;
  59.       count -= how_much;
  60.       if (read (input_han, out_buf_adr, how_much) != how_much)
  61.          return (3);
  62.       if (docrc)
  63.          addbfcrc (out_buf_adr, how_much);
  64.       if (output_han != -2)
  65.          if (write (output_han, out_buf_adr, how_much) != how_much)
  66.             return (2);
  67.    }
  68.    return (0);
  69. }
  70.  
  71.