Annotation of src/usr.bin/ssh/fdlim.h, Revision 1.2
1.1 deraadt 1: /*
2:
3: fdlim.h
4:
5: Author: David Mazieres <dm@lcs.mit.edu>
6: Contributed to be part of ssh.
7:
8: Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
9: All rights reserved
10:
11: Created: Tue Aug 22 17:21:32 1995 ylo
12:
13: */
14:
1.2 ! deraadt 15: /* RCSID("$Id: fdlim.h,v 1.1 1999/09/26 20:53:36 deraadt Exp $"); */
1.1 deraadt 16:
17: #ifndef FDLIM_H
18: #define FDLIM_H
19:
20: static int
21: fdlim_get (int hard)
22: {
23: struct rlimit rlfd;
1.2 ! deraadt 24:
1.1 deraadt 25: if (getrlimit (RLIMIT_NOFILE, &rlfd) < 0)
26: return (-1);
27: if ((hard ? rlfd.rlim_max : rlfd.rlim_cur) == RLIM_INFINITY)
28: return 10000;
29: else
30: return hard ? rlfd.rlim_max : rlfd.rlim_cur;
31: }
32:
33: static int
34: fdlim_set (int lim) {
35: struct rlimit rlfd;
36: if (lim <= 0)
37: return (-1);
38: if (getrlimit (RLIMIT_NOFILE, &rlfd) < 0)
39: return (-1);
40: rlfd.rlim_cur = lim;
41: if (setrlimit (RLIMIT_NOFILE, &rlfd) < 0)
42: return (-1);
43: return (0);
44: }
45:
46: #endif /* FDLIM_H */