/* block.c - Part of the unsea program.
 *   Copyright 1992 by David W. Rankin, Jr.
 * 
 * See "unsea.txt" for full copyright information applying 
 * to all text in this package. 
 *
 *
 * Contains ANSI C library functions for reading blocks of chars,
 * along with normal paranoia about error checking. :) */
 
#include "unsea.h"

int getfileblock(FILE *fp, unsigned char block[], const int blocksize)

{	size_t i=0;

	i = fread(block, 1, blocksize, fp);
	
	if ( (i != blocksize) || ferror(fp) || feof(fp) )
		return 1; /* something bad happened... */
	
	else return 0; /* This went OK... */
	
} /* end of getfileblock() */

int sendfileblock(FILE *fp, unsigned char block[], const int blocksize)

{	size_t i;

	i = fwrite(block, 1, blocksize, fp);
	
	if ( (i != blocksize) || ferror(fp) || feof(fp) )
		return 1; /* there was a file error, so tell it... */
	
	else return 0; /* a spotless finish.. */

} /* end of sendfileblock() */
