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:
parent
1061081619
commit
be92327e71
|
@ -17,4 +17,7 @@ static inline FILE *xfmkstemp(char **tmpname)
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
extern int get_fd_tabsize(void);
|
||||||
|
|
||||||
|
#endif /* UTIL_LINUX_FILEUTILS */
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <sys/resource.h>
|
||||||
|
|
||||||
#include "c.h"
|
#include "c.h"
|
||||||
#include "fileutils.h"
|
#include "fileutils.h"
|
||||||
|
@ -39,6 +41,28 @@ int xmkstemp(char **tmpname)
|
||||||
return fd;
|
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
|
#ifdef TEST_PROGRAM
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue