fork download
  1. int main(int argc, char** argv) {
  2.  
  3. if (argc != 3) {
  4. ::fprintf(stderr, "Usage: %s <filepath> <buffer size>\n", argv[0]);
  5. return 1;
  6. }
  7.  
  8. char* filename = argv[1];
  9. size_t buf_size = ::strtoul(argv[2], NULL, 10);;
  10.  
  11. if (buf_size == 0) {
  12. ::fprintf(stderr, "Usage: %s <filepath> <buffer size>\n", filename);
  13. ::fprintf(stderr, "<buffer size> must be greater than zero\n", filename);
  14. return 1;
  15. }
  16.  
  17. DWORD uBytesPerSector;
  18. DWORD uSectorsPerCluster;
  19.  
  20. ::GetDiskFreeSpace(NULL, &uSectorsPerCluster, &uBytesPerSector, NULL, NULL);
  21. ::fprintf(stderr, "info: byte per cluster %u\n", uBytesPerSector);
  22. ::fprintf(stderr, "info: secter per cluster %u\n", uSectorsPerCluster);
  23.  
  24. time_t u_start = time(NULL);
  25.  
  26. HANDLE hFile;
  27. DWORD uNumberOfBytesRead;
  28.  
  29. void* p_buf;
  30. hFile = ::CreateFile(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_NO_BUFFERING, NULL);
  31. if (hFile == INVALID_HANDLE_VALUE) {
  32. ::fprintf(stderr, "fatal error: open file error \"%s\"\n", filename);
  33. return 1;
  34. }
  35.  
  36. p_buf = ::malloc(buf_size);
  37.  
  38. do {
  39. if (!::ReadFile(hFile, p_buf, buf_size, &uNumberOfBytesRead, NULL)) {
  40. ::fprintf(stderr, "fatal error: %u bytes read error\n", buf_size);
  41. return 1;
  42. }
  43. } while (uNumberOfBytesRead == buf_size);
  44.  
  45. ::free(p_buf);
  46. ::fprintf(stdout, "%d\n", time(NULL) - u_start);
  47. return 0;
  48. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main(int, char**)’:
prog.cpp:4:3: error: ‘::fprintf’ has not been declared
   ::fprintf(stderr, "Usage: %s <filepath> <buffer size>\n", argv[0]);
   ^~
prog.cpp:4:13: error: ‘stderr’ was not declared in this scope
   ::fprintf(stderr, "Usage: %s <filepath> <buffer size>\n", argv[0]);
             ^~~~~~
prog.cpp:9:2: error: ‘size_t’ was not declared in this scope
  size_t buf_size = ::strtoul(argv[2], NULL, 10);;
  ^~~~~~
prog.cpp:11:6: error: ‘buf_size’ was not declared in this scope
  if (buf_size == 0) {
      ^~~~~~~~
prog.cpp:12:3: error: ‘::fprintf’ has not been declared
   ::fprintf(stderr, "Usage: %s <filepath> <buffer size>\n", filename);
   ^~
prog.cpp:12:13: error: ‘stderr’ was not declared in this scope
   ::fprintf(stderr, "Usage: %s <filepath> <buffer size>\n", filename);
             ^~~~~~
prog.cpp:13:3: error: ‘::fprintf’ has not been declared
   ::fprintf(stderr, "<buffer size> must be greater than zero\n", filename);
   ^~
prog.cpp:17:2: error: ‘DWORD’ was not declared in this scope
  DWORD uBytesPerSector;
  ^~~~~
prog.cpp:18:8: error: expected ‘;’ before ‘uSectorsPerCluster’
  DWORD uSectorsPerCluster;
        ^~~~~~~~~~~~~~~~~~
prog.cpp:20:2: error: ‘::GetDiskFreeSpace’ has not been declared
  ::GetDiskFreeSpace(NULL, &uSectorsPerCluster, &uBytesPerSector, NULL, NULL);
  ^~
prog.cpp:20:21: error: ‘NULL’ was not declared in this scope
  ::GetDiskFreeSpace(NULL, &uSectorsPerCluster, &uBytesPerSector, NULL, NULL);
                     ^~~~
prog.cpp:20:28: error: ‘uSectorsPerCluster’ was not declared in this scope
  ::GetDiskFreeSpace(NULL, &uSectorsPerCluster, &uBytesPerSector, NULL, NULL);
                            ^~~~~~~~~~~~~~~~~~
prog.cpp:20:49: error: ‘uBytesPerSector’ was not declared in this scope
  ::GetDiskFreeSpace(NULL, &uSectorsPerCluster, &uBytesPerSector, NULL, NULL);
                                                 ^~~~~~~~~~~~~~~
prog.cpp:21:2: error: ‘::fprintf’ has not been declared
  ::fprintf(stderr, "info: byte per cluster %u\n", uBytesPerSector);
  ^~
prog.cpp:21:12: error: ‘stderr’ was not declared in this scope
  ::fprintf(stderr, "info: byte per cluster %u\n", uBytesPerSector);
            ^~~~~~
prog.cpp:22:2: error: ‘::fprintf’ has not been declared
  ::fprintf(stderr, "info: secter per cluster %u\n", uSectorsPerCluster);
  ^~
prog.cpp:24:2: error: ‘time_t’ was not declared in this scope
  time_t u_start = time(NULL);
  ^~~~~~
prog.cpp:26:2: error: ‘HANDLE’ was not declared in this scope
  HANDLE hFile;
  ^~~~~~
prog.cpp:27:8: error: expected ‘;’ before ‘uNumberOfBytesRead’
  DWORD uNumberOfBytesRead;
        ^~~~~~~~~~~~~~~~~~
prog.cpp:30:2: error: ‘hFile’ was not declared in this scope
  hFile = ::CreateFile(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_NO_BUFFERING, NULL);
  ^~~~~
prog.cpp:30:10: error: ‘::CreateFile’ has not been declared
  hFile = ::CreateFile(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_NO_BUFFERING, NULL);
          ^~
prog.cpp:30:33: error: ‘GENERIC_READ’ was not declared in this scope
  hFile = ::CreateFile(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_NO_BUFFERING, NULL);
                                 ^~~~~~~~~~~~
prog.cpp:30:56: error: ‘OPEN_EXISTING’ was not declared in this scope
  hFile = ::CreateFile(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_NO_BUFFERING, NULL);
                                                        ^~~~~~~~~~~~~
prog.cpp:30:71: error: ‘FILE_ATTRIBUTE_NORMAL’ was not declared in this scope
  hFile = ::CreateFile(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_NO_BUFFERING, NULL);
                                                                       ^~~~~~~~~~~~~~~~~~~~~
prog.cpp:30:93: error: ‘FILE_FLAG_NO_BUFFERING’ was not declared in this scope
  hFile = ::CreateFile(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_NO_BUFFERING, NULL);
                                                                                             ^~~~~~~~~~~~~~~~~~~~~~
prog.cpp:31:15: error: ‘INVALID_HANDLE_VALUE’ was not declared in this scope
  if (hFile == INVALID_HANDLE_VALUE) {
               ^~~~~~~~~~~~~~~~~~~~
prog.cpp:32:3: error: ‘::fprintf’ has not been declared
   ::fprintf(stderr, "fatal error: open file error \"%s\"\n", filename);
   ^~
prog.cpp:36:10: error: ‘::malloc’ has not been declared
  p_buf = ::malloc(buf_size);
          ^~
prog.cpp:36:19: error: ‘buf_size’ was not declared in this scope
  p_buf = ::malloc(buf_size);
                   ^~~~~~~~
prog.cpp:39:8: error: ‘::ReadFile’ has not been declared
   if (!::ReadFile(hFile, p_buf, buf_size, &uNumberOfBytesRead, NULL)) {
        ^~
prog.cpp:39:44: error: ‘uNumberOfBytesRead’ was not declared in this scope
   if (!::ReadFile(hFile, p_buf, buf_size, &uNumberOfBytesRead, NULL)) {
                                            ^~~~~~~~~~~~~~~~~~
prog.cpp:40:4: error: ‘::fprintf’ has not been declared
    ::fprintf(stderr, "fatal error: %u bytes read error\n", buf_size);
    ^~
prog.cpp:43:11: error: ‘uNumberOfBytesRead’ was not declared in this scope
  } while (uNumberOfBytesRead == buf_size);
           ^~~~~~~~~~~~~~~~~~
prog.cpp:45:2: error: ‘::free’ has not been declared
  ::free(p_buf);
  ^~
prog.cpp:46:2: error: ‘::fprintf’ has not been declared
  ::fprintf(stdout, "%d\n", time(NULL) - u_start);
  ^~
prog.cpp:46:12: error: ‘stdout’ was not declared in this scope
  ::fprintf(stdout, "%d\n", time(NULL) - u_start);
            ^~~~~~
prog.cpp:46:37: error: ‘time’ was not declared in this scope
  ::fprintf(stdout, "%d\n", time(NULL) - u_start);
                                     ^
prog.cpp:46:41: error: ‘u_start’ was not declared in this scope
  ::fprintf(stdout, "%d\n", time(NULL) - u_start);
                                         ^~~~~~~
stdout
Standard output is empty