Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <fcntl.h>
  5. #define MAX 5
  6.  
  7. int main(int argc, char* argv[]){
  8. char buf[MAX];
  9. char buf2[MAX];
  10. int desc;
  11. int desc_k;
  12. int lbajt;
  13. long rozm;
  14. int x;
  15. int cof=-5;
  16. int t;
  17.  
  18. if (argc<3){
  19. fprintf(stderr, "Za malo argumentow. Uzyj:\n");
  20. fprintf(stderr, "%s <plik zrodlowy> <plik docelowy>\n", argv[0]);
  21. exit(1);
  22. }
  23.  
  24. desc = open(argv[1], O_RDONLY);
  25. if (desc == -1){
  26. perror("Blad otwarcia pliku");
  27. exit(1);
  28. }
  29.  
  30. rozm = lseek(desc, 0, SEEK_END);
  31. if (rozm == -1){
  32. perror("Blad w pozycjonowaniu");
  33. exit(1);
  34. }
  35.  
  36. printf("Rozmiar pliku %s: %ld\n", argv[1], rozm);
  37.  
  38.  
  39.  
  40. rozm = lseek(desc, cof, SEEK_END);
  41. if (rozm == -1){
  42. perror ("Blad w pozycjonowaniu");
  43. exit(1);
  44. }
  45.  
  46. desc_k=creat(argv[2], 0640);
  47. while((lbajt = read(desc, buf, MAX)) > 0){
  48. x=0;
  49. for(int i=4; i>=0; i--)
  50. {
  51. buf2[x]=buf[i];
  52. x++;
  53. }
  54. if (write(desc_k, buf2, lbajt) == -1){
  55. perror("Blad zapisu pliku docelowego");
  56. exit(1);
  57. }
  58. cof=cof-5;
  59. if((rozm+cof)<0)
  60. {
  61. t=rozm+cof;
  62. cof=cof-t;
  63.  
  64.  
  65. }
  66. rozm = lseek(desc, cof, SEEK_END);
  67. if (rozm == -1){
  68. perror ("Blad w pozycjonowaniu");
  69. exit(1);
  70. }
  71.  
  72. }
  73. exit(0);
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement