title: c - The permitted maximum of the "iovcnt" argument in "writev"?
body: <p>I've read man page for <code>writev</code> and found the ERRORS section notes that</p>
  
  <blockquote>
    <p>EINVAL ... the vector count <code>iovcnt</code> is less than zero or <strong>greater than the permitted maximum</strong>.</p>
  </blockquote>
  
  <p>But how could I get the max value?</p>
  
  <p>PS: On my OS (Ubuntu 14.04 x64) it seems to be 1024. I check it via the following code</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;sys/uio.h&gt;
  
  char content[4000];
  struct iovec vec[4000];
  
  int main()
  {
      int n, i;
      // int cnt = 1024; // OK
      int cnt = 1025; // writev error
      int fd = open("tmp.txt", O_WRONLY);
  
      if (fd == -1) {
          perror("open");
          exit(1);
      }
  
      for (i = 0; i &lt; cnt; ++i) {
          content[i] = 'a' + i % 26;
          vec[i].iov_base = content + i;
          vec[i].iov_len = 1;
      }
  
      n = writev(fd, vec, cnt);
      if (n == -1) {
          perror("writev");
          exit(1);
      }
      return 0;
  }
  </code></pre>