summaryrefslogtreecommitdiff
path: root/usr.bin/ssh/fdlim.h
blob: 616b6f4882f86f6ea62cb7aa33f982b93f91de91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*

fdlim.h

Author: David Mazieres <dm@lcs.mit.edu>
	Contributed to be part of ssh.

Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
                   All rights reserved

Created: Tue Aug 22 17:21:32 1995 ylo

*/

/* RCSID("$Id: fdlim.h,v 1.2 1999/09/30 05:43:33 deraadt Exp $"); */

#ifndef FDLIM_H
#define FDLIM_H

static int
fdlim_get (int hard)
{
  struct rlimit rlfd;

  if (getrlimit (RLIMIT_NOFILE, &rlfd) < 0)
    return (-1);
  if ((hard ? rlfd.rlim_max : rlfd.rlim_cur) == RLIM_INFINITY)
    return 10000;
  else
    return hard ? rlfd.rlim_max : rlfd.rlim_cur;
}

static int
fdlim_set (int lim) {
  struct rlimit rlfd;
  if (lim <= 0)
    return (-1);
  if (getrlimit (RLIMIT_NOFILE, &rlfd) < 0)
    return (-1);
  rlfd.rlim_cur = lim;
  if (setrlimit (RLIMIT_NOFILE, &rlfd) < 0)
    return (-1);
  return (0);
}

#endif /* FDLIM_H */