getdtablesize.c 852 B

1234567891011121314151617181920212223242526272829303132
  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. libc_hidden_proto(getdtablesize)
  13. libc_hidden_proto(getrlimit)
  14. #define __LOCAL_OPEN_MAX 256
  15. /* Return the maximum number of file descriptors
  16. the current process could possibly have. */
  17. int getdtablesize (void)
  18. {
  19. struct rlimit ru;
  20. /* This should even work if `getrlimit' is not implemented. POSIX.1
  21. does not define this function but we will generate a stub which
  22. returns -1. */
  23. return getrlimit (RLIMIT_NOFILE, &ru) < 0 ? __LOCAL_OPEN_MAX : ru.rlim_cur;
  24. }
  25. libc_hidden_def(getdtablesize)
  26. #endif