Advertisement
Guest User

Untitled

a guest
Nov 17th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.97 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <windows.h>
  4.  
  5. typedef struct Item
  6. {
  7.   INT value;
  8.   UINT next_pointer;
  9. } item_t;
  10.  
  11. int
  12. main(int argc, char *argv[])
  13. {
  14.   item_t current_item;
  15.   INT fd = -1, exit_code = 0;
  16.   if (argc < 2) {
  17.     exit_code = 1;
  18.     goto main_end;
  19.   }
  20.   INT item_count = 0;
  21.   HANDLE h_file = CreateFileA(argv[1], GENERIC_READ, FILE_SHARE_READ, NULL,
  22.                               OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  23.   if (h_file == INVALID_HANDLE_VALUE) {
  24.     exit_code = 1;
  25.     goto main_end;
  26.   }
  27.   DWORD dw_count;
  28.   while (ReadFile(h_file, &current_item, sizeof(item_t), &dw_count, NULL)) {
  29.     item_count++;
  30.     LARGE_INTEGER d_to_move;
  31.     d_to_move.QuadPart = current_item.next_pointer;
  32.     SetFilePointerEx(h_file, d_to_move, NULL, FILE_BEGIN);
  33.     printf("%d ", current_item.value);
  34.   }
  35.   if (item_count != 0) {
  36.     printf("%d ", current_item.value);
  37.   }
  38. main_end:
  39.   CloseHandle(h_file);
  40.   return exit_code;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement