Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Nov 18th, 2018 80 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. #include<sys/stat.h>
  2. #include<fcntl.h>
  3. #include<inttypes.h>
  4. #include<stdio.h>
  5.  
  6. #include<unistd.h>
  7.  
  8.  
  9. struct Item
  10. {
  11.     int value;
  12.     uint32_t next_pointer;
  13. };
  14.  
  15.  
  16. int
  17. main(int argc, char *argv[])
  18. {
  19.     int exit_code = 0;
  20.     int in_file = open(argv[1], O_RDONLY);
  21.     if (-1 == in_file) {
  22.         exit_code = 1;
  23.         goto finally;
  24.     }
  25.  
  26.     struct Item cur_item;
  27.     int in_read;
  28.  
  29.     while ((in_read = read(in_file, &cur_item, sizeof(struct Item))) > 0) {
  30.         printf("%d\n", cur_item.value);
  31.         uint32_t cur_next_pointer = cur_item.next_pointer;
  32.         if (cur_next_pointer == 0) {
  33.             break;
  34.         }
  35.         else {
  36.             int lseek_result = lseek(in_file, cur_next_pointer, SEEK_SET);
  37.             if (lseek_result == -1) {
  38.                 exit_code = 3;
  39.                 goto finally;
  40.             }
  41.         }
  42.     }
  43.  
  44.     if (-1 == in_read) {
  45.         exit_code = 2;
  46.         goto finally;
  47.     }
  48.  
  49.  
  50. finally:
  51.     close(in_file);
  52.     return exit_code;
  53. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top