Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <fcntl.h>
- #define MAX 5
- int main(int argc, char* argv[]){
- char buf[MAX];
- char buf2[MAX];
- int desc;
- int desc_k;
- int lbajt;
- long rozm;
- int x;
- int cof=-5;
- int t;
- if (argc<3){
- fprintf(stderr, "Za malo argumentow. Uzyj:\n");
- fprintf(stderr, "%s <plik zrodlowy> <plik docelowy>\n", argv[0]);
- exit(1);
- }
- desc = open(argv[1], O_RDONLY);
- if (desc == -1){
- perror("Blad otwarcia pliku");
- exit(1);
- }
- rozm = lseek(desc, 0, SEEK_END);
- if (rozm == -1){
- perror("Blad w pozycjonowaniu");
- exit(1);
- }
- printf("Rozmiar pliku %s: %ld\n", argv[1], rozm);
- rozm = lseek(desc, cof, SEEK_END);
- if (rozm == -1){
- perror ("Blad w pozycjonowaniu");
- exit(1);
- }
- desc_k=creat(argv[2], 0640);
- while((lbajt = read(desc, buf, MAX)) > 0){
- x=0;
- for(int i=4; i>=0; i--)
- {
- buf2[x]=buf[i];
- x++;
- }
- if (write(desc_k, buf2, lbajt) == -1){
- perror("Blad zapisu pliku docelowego");
- exit(1);
- }
- cof=cof-5;
- if((rozm+cof)<0)
- {
- t=rozm+cof;
- cof=cof-t;
- }
- rozm = lseek(desc, cof, SEEK_END);
- if (rozm == -1){
- perror ("Blad w pozycjonowaniu");
- exit(1);
- }
- }
- exit(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement