summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux/common/getdtablesize.c
blob: 4efd8280dc77616ce3468dadf6e1f6ff8e82885b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
 * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
 *
 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
 */

#include <stdlib.h>
#include <unistd.h>
#include <sys/resource.h>
#include <limits.h>

libc_hidden_proto(getdtablesize)

libc_hidden_proto(getrlimit)

#define __LOCAL_OPEN_MAX	    256

/* Return the maximum number of file descriptors
   the current process could possibly have.  */
int getdtablesize (void)
{
  struct rlimit ru;

  /* This should even work if `getrlimit' is not implemented.  POSIX.1
     does not define this function but we will generate a stub which
     returns -1.  */
  return getrlimit (RLIMIT_NOFILE, &ru) < 0 ? __LOCAL_OPEN_MAX : ru.rlim_cur;
}
libc_hidden_def(getdtablesize)