Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _GNU_SOURCE
- #include <sys/types.h>
- #include <sys/mman.h>
- #include <unistd.h>
- #include <string.h>
- #include <stdio.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <stdint.h>
- struct Item {
- int value;
- uint32_t next_pointer;
- };
- int main(int argc, char *argv[]) {
- char *file_name = argv[1];
- int fd = open(file_name, O_RDONLY);
- struct Item item;
- struct stat st;
- fstat(fd, &st);
- char *contents = mmap(NULL,
- st.st_size,
- PROT_READ,
- MAP_PRIVATE,
- fd,
- 0);
- size_t len = st.st_size;
- uint32_t entry = 0;
- memcpy(&item, contents, sizeof(item));
- while (item.next_pointer != 0) {
- printf("%d ", item.value);
- entry = item.next_pointer;
- memcpy(&item, contents + entry, sizeof(item));
- }
- printf("%d ", item.value);
- munmap(contents, st.st_size);
- finally:
- close(fd);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement