anutka

Untitled

Nov 30th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #include <sys/stat.h>
  2. #include <fcntl.h>
  3. #include <stdio.h>
  4. #include <unistd.h>
  5. #include <stdint.h>
  6.  
  7. struct Item {
  8. int value;
  9. uint32_t next_pointer;
  10. };
  11.  
  12. int main(int argc, char *argv[]) {
  13. int fd = open(argv[1], O_RDONLY);
  14.  
  15.  
  16. if (fd != -1) {
  17.  
  18. struct Item cur;
  19.  
  20. do{
  21. if (read(fd, &cur, sizeof(cur)) > 0){
  22. printf("%d\n",cur.value);
  23. lseek(fd, cur.next_pointer, SEEK_SET);
  24. } else {
  25. close(fd);
  26. return 0;
  27. }
  28. } while(cur.next_pointer != 0);
  29.  
  30. close(fd);
  31.  
  32. }
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment