lib/fileutils: add get_fd_tabsize()

as a fallback for the function getdtablesize()

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2012-04-23 13:52:41 +02:00
parent 1061081619
commit be92327e71
2 changed files with 28 additions and 1 deletions

View File

@ -17,4 +17,7 @@ static inline FILE *xfmkstemp(char **tmpname)
}
return ret;
}
#endif
extern int get_fd_tabsize(void);
#endif /* UTIL_LINUX_FILEUTILS */

View File

@ -6,6 +6,8 @@
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/resource.h>
#include "c.h"
#include "fileutils.h"
@ -39,6 +41,28 @@ int xmkstemp(char **tmpname)
return fd;
}
/*
* portable getdtablesize()
*/
int get_fd_tabsize(void)
{
int m;
#if defined(HAVE_GETDTABLESIZE)
m = getdtablesize();
#elif defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE)
struct rlimit rl;
getrlimit(RLIMIT_NOFILE, &rl);
m = rl.rlim_cur;
#elif defined(HAVE_SYSCONF) && defined(_SC_OPEN_MAX)
m = sysconf(_SC_OPEN_MAX);
#else
m = OPEN_MAX;
#endif
return m;
}
#ifdef TEST_PROGRAM
int main(void)
{