The function for posix is ​​given:

static uintmax_t wc(char const *fname) { static const auto BUFFER_SIZE = 16*1024; int fd = open(fname, O_RDONLY); if(fd == -1) handle_error("open"); /* Advise the kernel of our access pattern. */ posix_fadvise(fd, 0, 0, 1); // FDADVICE_SEQUENTIAL char buf[BUFFER_SIZE + 1]; uintmax_t lines = 0; while(size_t bytes_read = read(fd, buf, BUFFER_SIZE)) { if(bytes_read == (size_t)-1) handle_error("read failed"); if (!bytes_read) break; for(char *p = buf; (p = (char*) memchr(p, '\n', (buf + bytes_read) - p)); ++p) ++lines; } return lines; } 

I don’t understand two things how to pass the path in wchar_t (we have a modern code)) to the open function. The second point is, what exactly does posix_fadvise and how to adapt it under Windows?

  • Regarding what he does - man posix_fadvice - Fat-Zer
  • @ Fat-Zer, but is there any equivalent of the wind? Random is not this: msdn.microsoft.com/en-us/library/windows/desktop/… - User10155777
  • no, it looks like an analogue of posix_madvice () (not in Linux) ... I can't offer it - in winapi it is not strong ... - Fat-Zer
  • one
    Call CreateFileW with the FILE_FLAG_SEQUENTIAL_SCAN flag. - VTT
  • @VTT, issue as an answer. - User10155777

0