Advertisement
pochti_da

Untitled

Sep 29th, 2020
1,086
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 KB | None | 0 0
  1. #include <sys/types.h>
  2. #include <unistd.h>
  3. #include <stdio.h>
  4. #include <sys/stat.h>
  5. #include <fcntl.h>
  6.  
  7. int
  8. main(int argc, char *argv[])
  9. {
  10.     int fd = open(argv[1], O_RDWR);
  11.  
  12.     off_t min_ind = -1;
  13.     long long min, tmp;
  14.     for (off_t cnt = 0; read(fd, &tmp, sizeof(tmp)) == sizeof(tmp); cnt += sizeof(tmp)) {
  15.         if (min_ind == -1 || tmp < min) {
  16.             min = tmp;
  17.             min_ind = cnt;
  18.         }
  19.     }
  20.  
  21.     lseek(fd, min_ind, SEEK_SET);
  22.  
  23.     min = -min;
  24.     if (write(fd, &min, sizeof(min)) < sizeof(min)) {
  25.         return 1;
  26.     }
  27.  
  28.     close(fd);
  29.     return 0;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement