Commit 3b09597f authored by Per Cederqvist's avatar Per Cederqvist
Browse files

Initial commit.

parent 0319190b
/*
* Copyright (C) 2002 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
*
* LysKOM is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 1, or (at your option)
* any later version.
*
* LysKOM is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* along with LysKOM; see the file COPYING. If not, write to
* Lysator, c/o ISY, Linkoping University, S-581 83 Linkoping, SWEDEN,
* or the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
* MA 02139, USA.
*
* Please mail bug reports to bug-lyskom@lysator.liu.se.
*/
/*
* Test various ways of obtaining the number of available file descriptors.
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <limits.h>
#ifdef HAVE_SYS_RESOURCE_H
# ifdef TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
# else
# ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
# else
# include <time.h>
# endif
# endif
# include <sys/resource.h>
#else
# include <time.h>
#endif
#if defined(HAVE_SETRLIMIT) && defined(RLIMIT_OFILE) && !defined(RLIMIT_NOFILE)
# define RLIMIT_NOFILE RLIMIT_OFILE
#endif
#if !HAVE_RLIM_T
typedef int rlim_t;
#endif
int
main(void)
{
long getdtable = 0;
long openmax = 0;
long rlimmax = 0;
long sysconfmax = 0;
long max_seen = 0;
long fd;
#if defined(HAVE_SETRLIMIT) && defined(RLIMIT_NOFILE)
struct rlimit rlim;
#endif
#if HAVE_GETDTABLESIZE
getdtable = getdtablesize();
printf("getdtablesize: %ld\n", getdtable);
#endif
#ifdef OPEN_MAX
openmax = OPEN_MAX;
printf("OPEN_MAX: %ld\n", openmax);
#else
printf("OPEN_MAX: n/a\n");
#endif
#if defined(HAVE_SETRLIMIT) && defined(RLIMIT_NOFILE)
if (getrlimit(RLIMIT_NOFILE, &rlim) < 0)
{
perror("ERROR: testfd: getrlimit(RLIMIT_NOFILE) failed");
exit(1);
}
rlimmax = rlim.rlim_max;
printf("getrlimit-current: %ld\n", (long)rlim.rlim_cur);
printf("getrlimit-max: %ld\n", rlimmax);
#else
printf("getrlimit-current: n/a\n");
printf("getrlimit-max: n/a\n");
#endif
#if defined (HAVE_SYSCONF)
sysconfmax = sysconf(_SC_OPEN_MAX);
printf("sysconf: %ld\n", sysconfmax);
#else
printf("sysconf: n/a\n");
#endif
while(1)
{
fd = open("/dev/null", O_RDONLY);
if (fd < 0)
break;
if (fd >= max_seen)
max_seen = fd + 1;
}
printf("open: %ld\n", max_seen);
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment