Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <unistd.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/mman.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <time.h>
- #include <sys/stat.h>
- #include <stdint.h>
- #include <string.h>
- struct Item
- {
- int value;
- uint32_t next_pointer;
- };
- void find_items_layout(char* ptr) {
- struct Item *item = (struct Item*)ptr;
- printf("%d ", item->value);
- while (item->next_pointer != 0) {
- item = (struct Item*)(item->next_pointer + ptr);
- printf("%d ", item->value);
- }
- }
- int main(int argc, char* argv[]) {
- char *fname = argv[1];
- int fd = open(fname, O_RDONLY);
- if (fd == -1) {
- perror("failed to open file");
- return 2;
- }
- FILE * fp = fdopen(fd, "r");
- fseek(fp, 0, SEEK_END);
- int length = ftell(fp);
- char *ptr = mmap(NULL, length, PROT_READ, MAP_SHARED, fd, 0);
- if ((int64_t)ptr == -1) {
- perror("mmap failed");
- return 3;
- }
- find_items_layout(ptr);
- munmap(ptr, length);
- close(fd);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement