#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#define BUFFER_SIZE 4096
char input_buffer[BUFFER_SIZE];
char output_buffer[BUFFER_SIZE];
int main(int argc, char ** argv)
{
if(argc==1)
{
printf("usage: lyubcho_problem logfile\n");
exit(EXIT_FAILURE);
}
int fd=open(argv[1],O_RDONLY);
if(fd==-1)
{
perror(argv[1]);
exit(EXIT_FAILURE);
}
int read_bytes=0;
int written_bytes=0;
while((read_bytes=read(fd,input_buffer,BUFFER_SIZE))>0)
{
int i;
for(i=0;i<read_bytes;i++)
{
if(input_buffer[i]!='\0')
{
output_buffer[written_bytes++]=input_buffer[i];
if(written_bytes==BUFFER_SIZE)
{
write(1,output_buffer,written_bytes);
written_bytes=0;
}
}
}
}
write(1,output_buffer,written_bytes);
exit(EXIT_SUCCESS);
}