169c2ab0bc5c448c0e2c33510b710b22b19907f51Cyril Hrubis/*
269c2ab0bc5c448c0e2c33510b710b22b19907f51Cyril Hrubis * Copyright (C) 2012 Cyril Hrubis chrubis@suse.cz
369c2ab0bc5c448c0e2c33510b710b22b19907f51Cyril Hrubis *
469c2ab0bc5c448c0e2c33510b710b22b19907f51Cyril Hrubis * This program is free software; you can redistribute it and/or modify it
569c2ab0bc5c448c0e2c33510b710b22b19907f51Cyril Hrubis * under the terms of version 2 of the GNU General Public License as
669c2ab0bc5c448c0e2c33510b710b22b19907f51Cyril Hrubis * published by the Free Software Foundation.
769c2ab0bc5c448c0e2c33510b710b22b19907f51Cyril Hrubis *
869c2ab0bc5c448c0e2c33510b710b22b19907f51Cyril Hrubis * This program is distributed in the hope that it would be useful, but
969c2ab0bc5c448c0e2c33510b710b22b19907f51Cyril Hrubis * WITHOUT ANY WARRANTY; without even the implied warranty of
1069c2ab0bc5c448c0e2c33510b710b22b19907f51Cyril Hrubis * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1169c2ab0bc5c448c0e2c33510b710b22b19907f51Cyril Hrubis *
1269c2ab0bc5c448c0e2c33510b710b22b19907f51Cyril Hrubis * Further, this software is distributed without any warranty that it is
1369c2ab0bc5c448c0e2c33510b710b22b19907f51Cyril Hrubis * free of the rightful claim of any third person regarding infringement
1469c2ab0bc5c448c0e2c33510b710b22b19907f51Cyril Hrubis * or the like.  Any license provided herein, whether implied or
1569c2ab0bc5c448c0e2c33510b710b22b19907f51Cyril Hrubis * otherwise, applies only to this software file.  Patent licenses, if
1669c2ab0bc5c448c0e2c33510b710b22b19907f51Cyril Hrubis * any, provided herein do not apply to combinations of this program with
1769c2ab0bc5c448c0e2c33510b710b22b19907f51Cyril Hrubis * other software, or any other product whatsoever.
1869c2ab0bc5c448c0e2c33510b710b22b19907f51Cyril Hrubis *
1969c2ab0bc5c448c0e2c33510b710b22b19907f51Cyril Hrubis * You should have received a copy of the GNU General Public License along
2069c2ab0bc5c448c0e2c33510b710b22b19907f51Cyril Hrubis * with this program; if not, write the Free Software Foundation, Inc.,
2169c2ab0bc5c448c0e2c33510b710b22b19907f51Cyril Hrubis * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2269c2ab0bc5c448c0e2c33510b710b22b19907f51Cyril Hrubis */
2369c2ab0bc5c448c0e2c33510b710b22b19907f51Cyril Hrubis
24bbdb9f78378c7e038f463efa39d2470e1c51ad54Cyril Hrubis#ifndef TST_SAFE_FILE_OPS
25bbdb9f78378c7e038f463efa39d2470e1c51ad54Cyril Hrubis#define TST_SAFE_FILE_OPS
2669c2ab0bc5c448c0e2c33510b710b22b19907f51Cyril Hrubis
27bbdb9f78378c7e038f463efa39d2470e1c51ad54Cyril Hrubis#include "safe_file_ops_fn.h"
2869c2ab0bc5c448c0e2c33510b710b22b19907f51Cyril Hrubis
29bbdb9f78378c7e038f463efa39d2470e1c51ad54Cyril Hrubis#define SAFE_FILE_SCANF(path, fmt, ...) \
30bbdb9f78378c7e038f463efa39d2470e1c51ad54Cyril Hrubis	safe_file_scanf(__FILE__, __LINE__, NULL, \
31bbdb9f78378c7e038f463efa39d2470e1c51ad54Cyril Hrubis	                (path), (fmt), ## __VA_ARGS__)
3269c2ab0bc5c448c0e2c33510b710b22b19907f51Cyril Hrubis
339ff68def6cf6c7677532fd60857a68561c1fe384Jan Stancek#define FILE_LINES_SCANF(path, fmt, ...) \
349ff68def6cf6c7677532fd60857a68561c1fe384Jan Stancek	file_lines_scanf(__FILE__, __LINE__, NULL, 0,\
359ff68def6cf6c7677532fd60857a68561c1fe384Jan Stancek			(path), (fmt), ## __VA_ARGS__)
369ff68def6cf6c7677532fd60857a68561c1fe384Jan Stancek
379ff68def6cf6c7677532fd60857a68561c1fe384Jan Stancek#define SAFE_FILE_LINES_SCANF(path, fmt, ...) \
389ff68def6cf6c7677532fd60857a68561c1fe384Jan Stancek	file_lines_scanf(__FILE__, __LINE__, NULL, 1,\
399ff68def6cf6c7677532fd60857a68561c1fe384Jan Stancek			(path), (fmt), ## __VA_ARGS__)
409ff68def6cf6c7677532fd60857a68561c1fe384Jan Stancek
412c1bfc0d5febcfbdeb47ea150e29a121b49c7cfdLi Wang#define SAFE_READ_MEMINFO(item) \
422c1bfc0d5febcfbdeb47ea150e29a121b49c7cfdLi Wang       ({long tst_rval; \
432c1bfc0d5febcfbdeb47ea150e29a121b49c7cfdLi Wang        SAFE_FILE_LINES_SCANF("/proc/meminfo", item " %ld", \
442c1bfc0d5febcfbdeb47ea150e29a121b49c7cfdLi Wang                        &tst_rval); \
452c1bfc0d5febcfbdeb47ea150e29a121b49c7cfdLi Wang        tst_rval;})
462c1bfc0d5febcfbdeb47ea150e29a121b49c7cfdLi Wang
470b0e9171042fd1e2088ddb0800d83d4a5a7ffdf0Richard Palethorpe#define FILE_PRINTF(path, fmt, ...) \
480b0e9171042fd1e2088ddb0800d83d4a5a7ffdf0Richard Palethorpe	file_printf(__FILE__, __LINE__, \
490b0e9171042fd1e2088ddb0800d83d4a5a7ffdf0Richard Palethorpe		    (path), (fmt), ## __VA_ARGS__)
500b0e9171042fd1e2088ddb0800d83d4a5a7ffdf0Richard Palethorpe
51bbdb9f78378c7e038f463efa39d2470e1c51ad54Cyril Hrubis#define SAFE_FILE_PRINTF(path, fmt, ...) \
52bbdb9f78378c7e038f463efa39d2470e1c51ad54Cyril Hrubis	safe_file_printf(__FILE__, __LINE__, NULL, \
53bbdb9f78378c7e038f463efa39d2470e1c51ad54Cyril Hrubis	                 (path), (fmt), ## __VA_ARGS__)
5469c2ab0bc5c448c0e2c33510b710b22b19907f51Cyril Hrubis
55bbdb9f78378c7e038f463efa39d2470e1c51ad54Cyril Hrubis#define SAFE_CP(src, dst) \
56bbdb9f78378c7e038f463efa39d2470e1c51ad54Cyril Hrubis	safe_cp(__FILE__, __LINE__, NULL, (src), (dst))
5769c2ab0bc5c448c0e2c33510b710b22b19907f51Cyril Hrubis
58bbdb9f78378c7e038f463efa39d2470e1c51ad54Cyril Hrubis#define SAFE_TOUCH(pathname, mode, times) \
59bbdb9f78378c7e038f463efa39d2470e1c51ad54Cyril Hrubis	safe_touch(__FILE__, __LINE__, NULL, \
60bbdb9f78378c7e038f463efa39d2470e1c51ad54Cyril Hrubis			(pathname), (mode), (times))
6169c2ab0bc5c448c0e2c33510b710b22b19907f51Cyril Hrubis
62bbdb9f78378c7e038f463efa39d2470e1c51ad54Cyril Hrubis#endif /* TST_SAFE_FILE_OPS */
63