getdtablesize.c 790 B

123456789101112131415161718192021222324252627282930
  1. /*
  2. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  3. *
  4. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  5. */
  6. #include <stdlib.h>
  7. #include <unistd.h>
  8. #include <sys/resource.h>
  9. #include <limits.h>
  10. /* XXX: _BSD || _XOPEN_SOURCE >= 500 */
  11. #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  12. #define __LOCAL_OPEN_MAX 256
  13. /* Return the maximum number of file descriptors
  14. the current process could possibly have. */
  15. int getdtablesize (void)
  16. {
  17. struct rlimit ru;
  18. /* This should even work if `getrlimit' is not implemented. POSIX.1
  19. does not define this function but we will generate a stub which
  20. returns -1. */
  21. return getrlimit (RLIMIT_NOFILE, &ru) < 0 ? __LOCAL_OPEN_MAX : ru.rlim_cur;
  22. }
  23. libc_hidden_def(getdtablesize)
  24. #endif