SHARE
TWEET

4-4

Nasekoma Dec 15th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <unistd.h>
  2. #include <sys/wait.h>
  3. #include <stdlib.h>
  4. #include <fcntl.h>
  5. #include <stdio.h>
  6. #include <sys/stat.h>
  7. #include <limits.h>
  8. #include <inttypes.h>
  9.  
  10. int
  11. main(int argc, char *argv[])
  12. {
  13.     int fl = open(argv[1], O_RDWR);
  14.     long long num, min = LLONG_MAX;
  15.     int curofst = 0, minofst;
  16.     while (read(fl, &num, sizeof(num)) >= 0) {
  17.         if (num < min) {
  18.             min = num;
  19.             minofst = curofst;
  20.         }
  21.         curofst += sizeof(num);
  22.     }
  23.     if (min == LLONG_MIN) {
  24.         min = 0;
  25.     } else {
  26.         min = -min;
  27.     }
  28.     lseek(fl, SEEK_SET, minofst);
  29.     write(fl, &min, sizeof(min));
  30.     close(fl);
  31.     return 0;
  32. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top