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
use std::fs::File;
use std::io::Result;
use parsers::{map_result, parse_u64, read_to_end};
use nom::eol;
static FILE_MAX_PATH: &'static str = "/proc/sys/fs/file-max";
named!(parse_file_max<u64>,
do_parse!(max: parse_u64 >> eol >> (max))
);
pub fn file_max() -> Result<u64> {
let mut buf = [0;32];
let mut file = try!(File::open(FILE_MAX_PATH));
map_result(parse_file_max(try!(read_to_end(&mut file, &mut buf))))
}
#[cfg(test)]
pub mod tests {
use super::file_max;
#[test]
fn test_file_max() {
let max = file_max();
assert_eq!(max.is_ok(), true);
}
}