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. time_t u_start = time(NULL);
  18.  
  19. void* p_buf;
  20. ssize_t i_size;
  21. int fd = ::open(filename, O_RDONLY|O_LARGEFILE);
  22.  
  23. if (fd < 0) {
  24. ::fprintf(stderr, "fatal error: open file error \"%s\"\n", filename);
  25. return 1;
  26. }
  27.  
  28. p_buf = ::malloc(buf_size);
  29.  
  30. do {
  31. if ((i_size = ::read(fd, p_buf, buf_size)) < 0) {
  32. ::fprintf(stderr, "fatal error: %u bytes read error\n", buf_size);
  33. return 1;
  34. }
  35. } while (i_size == buf_size);
  36.  
  37. ::free(p_buf);
  38. ::fprintf(stdout, "%d\n", time(NULL) - u_start);
  39. return 0;
  40. }
  41.  
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: ‘time_t’ was not declared in this scope
  time_t u_start = time(NULL);
  ^~~~~~
prog.cpp:20:2: error: ‘ssize_t’ was not declared in this scope
  ssize_t i_size;
  ^~~~~~~
prog.cpp:21:11: error: ‘::open’ has not been declared
  int fd = ::open(filename, O_RDONLY|O_LARGEFILE);
           ^~
prog.cpp:21:28: error: ‘O_RDONLY’ was not declared in this scope
  int fd = ::open(filename, O_RDONLY|O_LARGEFILE);
                            ^~~~~~~~
prog.cpp:21:37: error: ‘O_LARGEFILE’ was not declared in this scope
  int fd = ::open(filename, O_RDONLY|O_LARGEFILE);
                                     ^~~~~~~~~~~
prog.cpp:24:3: error: ‘::fprintf’ has not been declared
   ::fprintf(stderr, "fatal error: open file error \"%s\"\n", filename);
   ^~
prog.cpp:24:13: error: ‘stderr’ was not declared in this scope
   ::fprintf(stderr, "fatal error: open file error \"%s\"\n", filename);
             ^~~~~~
prog.cpp:28:10: error: ‘::malloc’ has not been declared
  p_buf = ::malloc(buf_size);
          ^~
prog.cpp:28:19: error: ‘buf_size’ was not declared in this scope
  p_buf = ::malloc(buf_size);
                   ^~~~~~~~
prog.cpp:31:8: error: ‘i_size’ was not declared in this scope
   if ((i_size = ::read(fd, p_buf, buf_size)) < 0)  {
        ^~~~~~
prog.cpp:31:17: error: ‘::read’ has not been declared
   if ((i_size = ::read(fd, p_buf, buf_size)) < 0)  {
                 ^~
prog.cpp:32:4: error: ‘::fprintf’ has not been declared
    ::fprintf(stderr, "fatal error: %u bytes read error\n", buf_size);
    ^~
prog.cpp:32:14: error: ‘stderr’ was not declared in this scope
    ::fprintf(stderr, "fatal error: %u bytes read error\n", buf_size);
              ^~~~~~
prog.cpp:35:11: error: ‘i_size’ was not declared in this scope
  } while (i_size == buf_size);
           ^~~~~~
prog.cpp:37:2: error: ‘::free’ has not been declared
  ::free(p_buf);
  ^~
prog.cpp:38:2: error: ‘::fprintf’ has not been declared
  ::fprintf(stdout, "%d\n", time(NULL) - u_start);
  ^~
prog.cpp:38:12: error: ‘stdout’ was not declared in this scope
  ::fprintf(stdout, "%d\n", time(NULL) - u_start);
            ^~~~~~
prog.cpp:38:33: error: ‘NULL’ was not declared in this scope
  ::fprintf(stdout, "%d\n", time(NULL) - u_start);
                                 ^~~~
prog.cpp:38:37: error: ‘time’ was not declared in this scope
  ::fprintf(stdout, "%d\n", time(NULL) - u_start);
                                     ^
prog.cpp:38:41: error: ‘u_start’ was not declared in this scope
  ::fprintf(stdout, "%d\n", time(NULL) - u_start);
                                         ^~~~~~~
stdout
Standard output is empty