1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#define BUFLEN 4096
/* fout, fin : descripteurs fichiers sortie et entrée */
void reverse(int fout,int fin)
{
unsigned char bufin[BUFLEN],bufout[BUFLEN];
unsigned char *pi,*po;
int sstop=0;
long pseek,rlen=BUFLEN;
pseek=filelength(fin)-BUFLEN-1; /* -1:filelength() compte aussi EOF */ /* Provisoire */
if(pseek<0l) {
rlen=BUFLEN+pseek;
pseek=0l;
sstop=1;
}
printf("Processing .");
lseek(fin,pseek,SEEK_SET);
while(sstop<2) {
read(fin,bufin,(unsigned)rlen);
setmem(bufout,BUFLEN,0);
pi=bufin+(unsigned)rlen-1;
po=bufout;
while(pi>=bufin) *po++=*pi--;
write(fout,bufout,(unsigned)rlen);
pseek-=2l*BUFLEN;
if(pseek<0l) {
rlen=BUFLEN+pseek;
pseek=0l;
sstop++;
}
if(sstop<2) {
putchar('.');
lseek(fin,pseek,SEEK_SET);
}
}
printf("\n");
}
void main(int argc,char *argv[])
{
int fhin,fhout;
char tmp[80];
fhin=open(argv[1],O_BINARY|O_RDONLY,S_IREAD|S_IWRITE);
fhout=open(argv[2],O_BINARY|O_WRONLY|O_CREAT|O_TRUNC,S_IREAD|S_IWRITE);
reverse(fhout,fhin);
close(fhout);
close(fhin);
} |
Partager