32 lines
697 B
C
32 lines
697 B
C
|
#include <sys/types.h>
|
||
|
#include <sys/stat.h>
|
||
|
#include <unistd.h>
|
||
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <wait.h>
|
||
|
#include <fcntl.h>
|
||
|
de
|
||
|
|
||
|
int main(int argc, char **argv){
|
||
|
if (argc != 3){
|
||
|
printf("Usage : %s <FILE1> <FILE2> | This program compares two files and is able to detect if they are different or same\n", argv[0]);
|
||
|
return EXIT_FAILURE;
|
||
|
}
|
||
|
pid_t p;
|
||
|
int fd1, fd2;
|
||
|
char buf[BUF_SIZE];
|
||
|
fd1 = open(argv[1], O_RDONLY);
|
||
|
fd2 = open(argv[2], O_RDONLY);
|
||
|
if (fd1 == -1 || fd2 == -1){
|
||
|
perror("Error while opening files");
|
||
|
return EXIT_FAILURE;
|
||
|
}
|
||
|
p = fork();
|
||
|
switch(p){
|
||
|
case -1:
|
||
|
perror("Error while creating a new process");
|
||
|
return EXIT_FAILURE;
|
||
|
case 0:
|
||
|
while(read
|
||
|
|