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