]> git.ipfire.org Git - thirdparty/util-linux.git/blob - lib/caputils.c
scriptreplay: check for EOF
[thirdparty/util-linux.git] / lib / caputils.c
1 /*
2 * This program is free software; you can redistribute it and/or modify it
3 * under the terms of the GNU General Public License as published by the
4 * Free Software Foundation; either version 2, or (at your option) any
5 * later version.
6 *
7 * This program is distributed in the hope that it will be useful, but
8 * WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License along
13 * with this program; if not, write to the Free Software Foundation, Inc.,
14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15 */
16
17 #include <stdio.h>
18
19 #include "caputils.h"
20 #include "pathnames.h"
21
22 int cap_last_cap(void)
23 {
24 /* CAP_LAST_CAP is untrustworthy. */
25 static int ret = -1;
26 int matched;
27 FILE *f;
28
29 if (ret != -1)
30 return ret;
31
32 f = fopen(_PATH_PROC_CAPLASTCAP, "r");
33 if (!f) {
34 ret = CAP_LAST_CAP; /* guess */
35 return ret;
36 }
37
38 matched = fscanf(f, "%d", &ret);
39 fclose(f);
40
41 if (matched != 1)
42 ret = CAP_LAST_CAP; /* guess */
43
44 return ret;
45 }