If we are just copying data from one file to another, we don't need to fill a complete buffer, just read a chunk at a time, and write it to the output.
		
			
				
	
	
		
			24 lines
		
	
	
		
			398 B
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			24 lines
		
	
	
		
			398 B
		
	
	
	
		
			C
		
	
	
	
	
	
/* See LICENSE file for copyright and license details. */
 | 
						|
#include <unistd.h>
 | 
						|
 | 
						|
#include "../util.h"
 | 
						|
 | 
						|
int
 | 
						|
concat(int f1, const char *s1, int f2, const char *s2)
 | 
						|
{
 | 
						|
	char buf[BUFSIZ];
 | 
						|
	ssize_t n;
 | 
						|
 | 
						|
	while ((n = read(f1, buf, sizeof(buf))) > 0) {
 | 
						|
		if (writeall(f2, buf, n) < 0) {
 | 
						|
			weprintf("write %s:", s2);
 | 
						|
			return -2;
 | 
						|
		}
 | 
						|
	}
 | 
						|
	if (n < 0) {
 | 
						|
		weprintf("read %s:", s1);
 | 
						|
		return -1;
 | 
						|
	}
 | 
						|
	return 0;
 | 
						|
}
 |