libite/fsendfile.c
/**
 * fsendfile - copy data between file streams
 * @src: Source stream
 * @dst: Destination stream
 * @len: Number of bytes to copy
 *
 * @dst may be %NULL, in which case @len bytes are read and discarded
 * from @src.  This can be useful for streams where seeking is not
 * permitted.  Additionally, @len may be the special value zero (0), in
 * which case fsendfile() will copy until %EOF is seen on @src.
 *
 * Returns:
 * The number of bytes copied.  If an error is detected -1 is returned
 * and @errno will be set accordingly.
 */
copy data between file streams
@src: Source stream
@dst: Destination stream
@len: Number of bytes to copy

@dst may be %NULL, in which case @len bytes are read and discarded
from @src.  This can be useful for streams where seeking is not
permitted.  Additionally, @len may be the special value zero (0), in
which case fsendfile() will copy until %EOF is seen on @src.

The number of bytes copied.  If an error is detected -1 is returned
and @errno will be set accordingly.
copy data between file streams @src : Source stream @dst : Destination stream @len : Number of bytes to copy @dst may be %NULL in which case @len bytes are read and discarded from @src . This can be useful for streams where seeking is not permitted . Additionally @len may be the special value zero ( 0 ) in which case fsendfile () will copy until %EOF is seen on @src . The number of bytes copied . If an error is detected - 1 is returned and @errno will be set accordingly .
size_t fsendfile(FILE *src, FILE *dst, size_t len)
{
	char *buf;
	size_t blk = BUFSIZ, num = 0, tot = 0;
        if (!src) {
                errno = EINVAL;
                return -1;
        }
	buf = (char *)malloc(BUFSIZ);
	if (!buf)
		return -1;
	while (!len || tot < len) {
		if (len && ((len - tot) < BUFSIZ))
			blk = len - tot;
		num = fread(buf, 1, blk, src);
		if (num == 0)
			break;
		if (dst && (fwrite(buf, num, 1, dst) != 1)) {
			num = -1;
			break;
		}
		tot += num;
	}
	free(buf);
	return (num == (size_t)-1) ? (size_t)-1 : tot;
}
size_t fsendfile ( FILE * src , FILE * dst , size_t len ) { char * buf ; size_t blk = BUFSIZ , num = 0 , tot = 0 ; if ( ! src ) { errno = EINVAL ; return -1 ; } buf = ( char * ) malloc ( BUFSIZ ) ; if ( ! buf ) return -1 ; while ( ! len || tot < len ) { if ( len && ( ( len - tot ) < BUFSIZ ) ) blk = len - tot ; num = fread ( buf , 1 , blk , src ) ; if ( num == 0 ) break ; if ( dst && ( fwrite ( buf , num , 1 , dst ) != 1 ) ) { num = -1 ; break ; } tot += num ; } free ( buf ) ; return ( num == ( size_t ) -1 ) ? ( size_t ) -1 : tot ; }
fsendfile - copy data between file streams
 @src: Source stream
 @dst: Destination stream
 @len: Number of bytes to copy
fsendfile - copy data between file streams @src : Source stream @dst : Destination stream @len : Number of bytes to copy