• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright (C) 2012 Cyril Hrubis chrubis@suse.cz
3  */
4 
5 #ifndef TST_SAFE_FILE_OPS
6 #define TST_SAFE_FILE_OPS
7 
8 #include "safe_file_ops_fn.h"
9 
10 #define FILE_SCANF(path, fmt, ...) \
11 	file_scanf(__FILE__, __LINE__, (path), (fmt), ## __VA_ARGS__)
12 
13 #define SAFE_FILE_SCANF(path, fmt, ...) \
14 	safe_file_scanf(__FILE__, __LINE__, NULL, \
15 	                (path), (fmt), ## __VA_ARGS__)
16 
17 #define FILE_LINES_SCANF(path, fmt, ...) \
18 	file_lines_scanf(__FILE__, __LINE__, NULL, 0,\
19 			(path), (fmt), ## __VA_ARGS__)
20 
21 #define SAFE_FILE_LINES_SCANF(path, fmt, ...) \
22 	file_lines_scanf(__FILE__, __LINE__, NULL, 1,\
23 			(path), (fmt), ## __VA_ARGS__)
24 
25 #define SAFE_READ_MEMINFO(item) \
26        ({long tst_rval; \
27         SAFE_FILE_LINES_SCANF("/proc/meminfo", item " %ld", \
28                         &tst_rval); \
29         tst_rval;})
30 
31 #define SAFE_READ_PROC_STATUS(pid, item) \
32        ({long tst_rval_; \
33         char tst_path_[128]; \
34         sprintf(tst_path_, "/proc/%d/status", pid); \
35         SAFE_FILE_LINES_SCANF(tst_path_, item " %ld", \
36                         &tst_rval_); \
37         tst_rval_;})
38 
39 #define FILE_PRINTF(path, fmt, ...) \
40 	file_printf(__FILE__, __LINE__, \
41 		    (path), (fmt), ## __VA_ARGS__)
42 
43 #define SAFE_FILE_PRINTF(path, fmt, ...) \
44 	safe_file_printf(__FILE__, __LINE__, NULL, \
45 	                 (path), (fmt), ## __VA_ARGS__)
46 
47 /* Same as SAFE_FILE_PRINTF() but returns quietly if the path doesn't exist */
48 #define SAFE_TRY_FILE_PRINTF(path, fmt, ...) \
49 	safe_try_file_printf(__FILE__, __LINE__, NULL, \
50 		(path), (fmt), ## __VA_ARGS__)
51 
52 #define SAFE_CP(src, dst) \
53 	safe_cp(__FILE__, __LINE__, NULL, (src), (dst))
54 
55 #define SAFE_TOUCH(pathname, mode, times) \
56 	safe_touch(__FILE__, __LINE__, NULL, \
57 			(pathname), (mode), (times))
58 
59 #define SAFE_MOUNT_OVERLAY() \
60 	((void) mount_overlay(__FILE__, __LINE__, 1))
61 
62 #define TST_MOUNT_OVERLAY() \
63 	(mount_overlay(__FILE__, __LINE__, 0) == 0)
64 
65 #endif /* TST_SAFE_FILE_OPS */
66