Ajout de l'exo 1 TP2

This commit is contained in:
Tom MOGULJAK 2023-09-14 16:01:56 +02:00
parent d8f9b69558
commit 22fc1af266
3 changed files with 74 additions and 1 deletions

View File

@ -283,3 +283,5 @@ XXXXXXXX BB BB BB BB BB BB BB BB BB BB BB BB BB BB BB BB |CCCCCCCCCCCCCCCC|
>Est-ce conforme à ce que l'on a vu en cours concernant l'alignement en mémoire ?
>L'alignement en mémoire est conforme à ce que l'on a vu en cours car les adresses sont alignées sur 16 octets.
# TP 2 : Fichiers

35
TP2/Exo1/copy.c Normal file
View File

@ -0,0 +1,35 @@
#include <fcntl.h>
#include <unistd.h>
#include <assert.h>
#define BLOCK_SIZE 1
int main(int argc, char *argv[])
{
int fin,
fout;
char buf[BLOCK_SIZE];
assert( argc == 3 );
fin = open(argv[1],O_RDONLY);
assert( fin >= 0 );
fout = open(argv[2],O_CREAT|O_WRONLY|O_TRUNC,0600);
assert( fout >= 0 );
while(1){
ssize_t nb_read;
nb_read = read(fin,buf,BLOCK_SIZE);
if (nb_read <= 0)
break;
write(fout,buf,nb_read);
}
close(fin);
close(fout);
return 0;
}

36
TP2/Exo1/copy2.c Normal file
View File

@ -0,0 +1,36 @@
#include <unistd.h>
#include <assert.h>
#include <stdio.h>
#define BLOCK_SIZE 1
int main(int argc, char *argv[])
{
FILE *fin,
*fout;
char buf[BLOCK_SIZE];
assert( argc == 3 );
fin = fopen(argv[1],"r");
assert( fin >= 0 );
fout = fopen(argv[2],"w");
assert( fout >= 0 );
while(1){
ssize_t nb_read;
nb_read = fread(buf,BLOCK_SIZE,1,fin);
if (nb_read <= 0)
break;
fwrite(buf,nb_read,1,fout);
}
fclose(fin);
fclose(fout);
return 0;
}