correction partielle

This commit is contained in:
2025-09-11 18:41:42 +02:00
parent 5cf4205f52
commit cc6f30529e
3 changed files with 141 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
#include <fcntl.h>
#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 != NULL );
fout = fopen(argv[2],"w");
assert( fout != NULL );
while(1){
ssize_t nb_read;
nb_read = fread(buf,BLOCK_SIZE,1,fin);
if (nb_read <= 0)
break;
fwrite(buf,BLOCK_SIZE,nb_read,fout);
}
fclose(fin);
fclose(fout);
return 0;
}

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;
}

View File

@@ -0,0 +1,70 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <assert.h>
#include <time.h>
#include <sys/mman.h>
#define BUFSIZE 1024
static inline double tstamp(void)
{
struct timespec tv;
clock_gettime(CLOCK_REALTIME, &tv);
return tv.tv_sec + tv.tv_nsec * 1.0e-9;
}
int main(int argc, char *argv[])
{
//char buf[BUFSIZE];
char * bufin = NULL,
* bufout = NULL;
int fin,
fout;
double start,
end;
size_t filesize = 0;
assert(argc == 3);
start = tstamp();
fin = open(argv[1],O_RDONLY);
assert(fin >=0);
fout = open(argv[2],O_RDWR|O_CREAT|O_TRUNC,0600);
assert(fout >=0);
filesize = lseek(fin,0,SEEK_END);
ftruncate (fout,filesize);
bufin = mmap(NULL,filesize,PROT_READ,MAP_PRIVATE,fin,0);
assert(bufin != (void*)-1);
bufout = mmap(NULL,filesize,PROT_WRITE,MAP_SHARED,fout,0);
assert(bufout != (void*)-1);
memcpy(bufout,bufin,filesize);
//munmap(bufin,filesize);
//munmap(bufout,filesize);
//ssize_t nb_read = read(fin,buf,sizeof(buf));
close(fin);
close(fout);
end = tstamp();
printf("time = %.3lf\n",end - start);
return 0;
}