home *** CD-ROM | disk | FTP | other *** search
- #ifndef LINT
- static char sccsid[]="@(#) getfile.c 1.2 87/05/03 16:00:59";
- #endif /* LINT */
-
- /*
- Copyright (C) 1986, 1987 Rahul Dhesi -- All rights reserved
- */
-
- #include "options.h"
- /*
- This function copies n characters from the source file to the destination
-
- Input: output_han: handle of destination file.
- input_han: handle of source file.
- count: count of characters to copy.
- docrc: 0 if crc not wanted
-
- If count is -1, copying is done until eof is encountered.
-
- The source file is transferred to the current file pointer position in the
- destination file, using the handles provided. Function return value is 0
- if no error, 2 if write error, and 3 if read error.
-
- Note, however, that if the output handle is -2, it is taken to be the
- null device and no output actually occurs.
-
- If docrc is not 0, the global variable crccode is updated via addbfcrc().
- This is done even if the output is to the null device.
- */
-
- #include <stdio.h>
- #include "various.h"
- #include "zoofns.h"
- #include "zoomem.h"
-
- int getfile(input_han, output_han, count, docrc)
- int input_han, output_han;
- long count;
- int docrc;
- {
- register int how_much;
-
- if (count == -1) {
- while ((how_much = read (input_han, out_buf_adr, MEM_BLOCK_SIZE)) > 0) {
- if (how_much == -1 ||
- write (output_han, out_buf_adr, how_much) != how_much)
- return (2);
- if (docrc)
- addbfcrc (out_buf_adr,how_much);
- }
- return (0);
- }
-
- while (count > 0) {
- if (count > MEM_BLOCK_SIZE)
- how_much = MEM_BLOCK_SIZE;
- else
- how_much = count;
- count -= how_much;
- if (read (input_han, out_buf_adr, how_much) != how_much)
- return (3);
- if (docrc)
- addbfcrc (out_buf_adr, how_much);
- if (output_han != -2)
- if (write (output_han, out_buf_adr, how_much) != how_much)
- return (2);
- }
- return (0);
- }
-
-