getdtablesize.c 751 B

1234567891011121314151617181920212223242526272829
  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. libc_hidden_proto(getdtablesize)
  11. libc_hidden_proto(getrlimit)
  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)