Public feed #890895

Anonymous

public c v1 · immutable
Raw Edit
·published 2008-02-04 04:34 UTC
rendered paste body
#include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>#define BUFFER_SIZE (99 * 1024)int main(int argc, char *argv[]){	char buffer[BUFFER_SIZE];	int read_size;	int in_file;	int out_file;	int ch; //EOF	if(argc != 3){		fprintf(stderr, "Error: Wrong number of arguments\n");		fprintf(stderr, "Usage is copy <from> <to>\n");		exit(8);	}	in_file = open(argv[1], O_RDONLY);	if(in_file < 0){		fprintf(stderr, "Error: Unable to open %s\n",argv[1]);		exit(8);	}	out_file = open(argv[2], O_RDWR|O_TRUNC|O_CREAT, 0666);	if(out_file < 0){		fprintf(stderr, "Error: Unable to open %s\n",argv[2]);		exit(8);	}		while(1){		read_size = read(in_file, buffer, sizeof(buffer));		if(read_size == 0)			break;		if(read_size < 0){			fprintf(stderr, "Error: Read error\n");			exit(8);		}		write(out_file, buffer, (unsigned int) read_size);			}		while(ch != EOF){		ch = fgetc(out_file);		if(ch == '\t')		{		fputs("     ", out_file);			}	}		close(in_file);	close(out_file);	return 0;}