title: Is it reasonable to expect that in Linux, fd < maximum number of open file descriptors?
body: <p>I'm writing a server that needs to handle many open sockets, so I use <code>setrlimit()</code> to set the maximum number of open file descriptors (as root, before dropping privileges) like so:</p>
  
  <pre><code>#include &lt;sys/resource.h&gt;
  #define MAX_FD_C 9001
  
  if (setrlimit(
        RLIMIT_NOFILE, &amp;(struct rlimit){.rlim_cur = MAX_FD_C, .rlim_max = MAX_FD_C}
      ) == -1) {
      perror("Failed to set the maximum number of open file descriptors");
      return EXIT_FAILURE;
  }
  </code></pre>
  
  <p>Now, I realize there probably won't be any guarantees and that I'm at the mercy of whatever method the Linux kernel uses to implements file descriptor tables; but in practice, is it reasonable to assume that any fd this program receives from the Linux kernel will have a value less than the MAX_FD_C I set above?</p>
  
  <p>I'd like to keep per socket data as compact as possible which could mean simply using an array like <code>static struct client clients[MAX_FD_C] = {{0}};</code> and using the fd as the index to the client struct (which would basically be my own version of the FDT).</p>