• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2017 Xiao Yang <yangx.jy@cn.fujitsu.com>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef SPLICE_H__
19 #define SPLICE_H__
20 
21 #include <unistd.h>
22 #include "tst_safe_file_ops.h"
23 #include "tst_minmax.h"
24 
get_max_limit(int default_len_data)25 static inline int get_max_limit(int default_len_data)
26 {
27 	int pipe_max_unpriv;
28 
29 	if (!access("/proc/sys/fs/pipe-max-size", F_OK)) {
30 		SAFE_FILE_SCANF("/proc/sys/fs/pipe-max-size", "%d", &pipe_max_unpriv);
31 		return MIN(pipe_max_unpriv, default_len_data);
32 	}
33 
34 	if (!access("/proc/sys/fs/pipe-max-pages", F_OK)) {
35 		SAFE_FILE_SCANF("/proc/sys/fs/pipe-max-pages", "%d", &pipe_max_unpriv);
36 		return MIN(pipe_max_unpriv * getpagesize(), default_len_data);
37 	}
38 
39 	return default_len_data;
40 }
41 
42 #endif  /* SPLICE_H__ */
43