Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/types.h>
- #include <unistd.h>
- #include <stdio.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <limits.h>
- int
- main(int argc, char *argv[])
- {
- int fd;
- if ((fd = open(argv[1], O_RDWR)) == -1) {
- return 1;
- }
- off_t min_ind = -1, cnt = 0;
- long long min, tmp;
- while (read(fd, &tmp, sizeof(tmp)) == sizeof(tmp)) {
- if (min_ind == -1 || tmp < min) {
- min = tmp;
- min_ind = cnt;
- }
- cnt += sizeof(tmp);
- }
- if (lseek(fd, min_ind, SEEK_SET) == -1) {
- return 0;
- }
- if (min != LLONG_MIN) {
- min = -min;
- }
- if (write(fd, &min, sizeof(min)) != sizeof(min)) {
- return 1;
- }
- close(fd);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement