Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #include <string.h>
- #include <limits.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- int main(int argc, char *argv[])
- {
- int fd = open(argv[1], O_RDONLY);
- int flag = 1;
- long offset = atol(argv[2]);
- lseek(fd, offset, SEEK_SET);
- size_t res_sz = 0, res_elem = 0;
- unsigned short size;
- size_t result = read(fd, &size, sizeof(unsigned short));
- if (!result) {
- return 0;
- }
- lseek(fd, size, SEEK_CUR);
- long long offset_f;
- read (fd, &offset_f, sizeof(long long));
- res_sz += size;
- ++(res_elem);
- if (!offset_f) {
- return 0;
- }
- long long record_size = size + sizeof(unsigned short) + sizeof(long long);
- lseek(fd, offset_f - record_size, SEEK_CUR);
- while (flag)
- {
- unsigned short buf1;
- read (fd, &buf1, sizeof(unsigned short));
- lseek(fd, buf1, SEEK_CUR);
- long long buf2;
- read(fd, &buf2, sizeof(long long));
- res_sz += buf1;
- ++(res_elem);
- if (buf2) {
- record_size = buf1 + sizeof(unsigned short) + sizeof(long long);
- lseek(fd, buf2 - record_size, SEEK_CUR);
- flag = 1;
- } else {
- flag = 0;
- }
- }
- printf("%u\n", res_elem);
- printf("%u\n", res_sz);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement