This commit is contained in:
2025-09-18 14:06:06 +02:00
parent 0be5f67093
commit bbb9f49737
14 changed files with 442 additions and 0 deletions

BIN
SCR3.1/TP2/Ex4/Comparaison Executable file

Binary file not shown.

View File

@@ -0,0 +1,74 @@
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <string.h>
#include <errno.h>
#define BUFFER_SIZE 4096
int main(int argc, char *argv[]) {
if (argc != 3) {
fprintf(stderr, "Usage: %s <file1> <file2>\n", argv[0]);
return 1;
}
const char *file1 = argv[1];
const char *file2 = argv[2];
struct stat stat1, stat2;
if (stat(file1, &stat1) == -1) {
perror("Erreur stat file1");
return 1;
}
if (stat(file2, &stat2) == -1) {
perror("Erreur stat file2");
return 1;
}
if (stat1.st_size != stat2.st_size) {
return 1;
}
int fd1 = open(file1, O_RDONLY);
if (fd1 == -1) {
perror("Erreur open file1");
return 1;
}
int fd2 = open(file2, O_RDONLY);
if (fd2 == -1) {
perror("Erreur open file2");
close(fd1);
return 1;
}
char buffer1[BUFFER_SIZE];
char buffer2[BUFFER_SIZE];
ssize_t bytes_read1, bytes_read2;
while ((bytes_read1 = read(fd1, buffer1, BUFFER_SIZE)) > 0) {
bytes_read2 = read(fd2, buffer2, BUFFER_SIZE);
if (bytes_read2 != bytes_read1 || memcmp(buffer1, buffer2, bytes_read1) != 0) {
close(fd1);
close(fd2);
return 1;
}
}
if (bytes_read1 == -1) {
perror("Erreur lecture file1");
close(fd1);
close(fd2);
return 1;
}
close(fd1);
close(fd2);
return 0;
}

BIN
SCR3.1/TP2/Ex4/test.data Normal file

Binary file not shown.

BIN
SCR3.1/TP2/Ex4/test.data2 Normal file

Binary file not shown.