1 /* Utilities functions to read/parse Linux procfs and sysfs.
2 Copyright (C) 2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
24 typedef int (*procutils_closure_t
) (const char *line
, void *arg
);
26 #define PROCUTILS_MAX_LINE_LEN 256
28 /* Open and read the path FILENAME, line per line, and call CLOSURE with
29 argument ARG on each line. The read is done with a static buffer,
30 with non-cancellable calls, and the line is null terminated.
32 The CLOSURE should return 0 if the read should continue, otherwise the
33 the function should stop and return early.
35 The '\n' is not included in the CLOSURE input argument and lines longer
36 than PROCUTILS_MAX_LINE_LEN characteres are ignored.
38 It returns true in case the file is fully read or false if CLOSURE
39 returns a value diferent than 0. */
40 bool procutils_read_file (const char *filename
, procutils_closure_t closure
,
41 void *arg
) attribute_hidden
;