static int get_open_max(void)
{
  int open_max = -1;
  /* SCO OpenServer has an fcntl() to retrieve the highest *currently
	 open* file descriptor.  */
#ifdef F_GETHFDO
  if ((open_max = fcntl(-1, F_GETHFDO, 0)) >= 0)
	return open_max + 1;
#endif
  /* IEEE Std 1003.1-2001/Cor 1-2002 clarified the fact that return
	 value of sysconf(_SC_OPEN_MAX) may change if setrlimit() was
	 called to set RLIMIT_NOFILE. So, we should be on the safe side to
	 call getrlimit() first to get the soft limit.

	 Note: dgettablesize() was a possibility but (i) it's equivalent
	 to getrlimit(), and (ii) it is not recommended for new code.  */
  struct rlimit ru;
  if (getrlimit(RLIMIT_NOFILE, &ru) == 0)
	return ru.rlim_cur;
  if ((open_max = sysconf(_SC_OPEN_MAX)) >= 0)
	return open_max;
  /* XXX: simply guess something reasonable.  */
  return 256;
}
static int get_open_max(void)
{
  int open_max = -1;
   
#ifdef F_GETHFDO
  if ((open_max = fcntl(-1, F_GETHFDO, 0)) >= 0)
	return open_max + 1;
#endif
   
  struct rlimit ru;
  if (getrlimit(RLIMIT_NOFILE, &ru) == 0)
	return ru.rlim_cur;
  if ((open_max = sysconf(_SC_OPEN_MAX)) >= 0)
	return open_max;
   
  return 256;
}