Home | History | Annotate | Download | only in old
      1 /*
      2  * Copyright (c) 2012-2016 Cyril Hrubis <chrubis (at) suse.cz>
      3  *
      4  * This program is free software: you can redistribute it and/or modify
      5  * it under the terms of the GNU General Public License as published by
      6  * the Free Software Foundation, either version 2 of the License, or
      7  * (at your option) any later version.
      8  *
      9  * This program is distributed in the hope that it will be useful,
     10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12  * GNU General Public License for more details.
     13  *
     14  * You should have received a copy of the GNU General Public License
     15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
     16  */
     17 
     18  /*
     19 
     20    This code helps with file reading/writing files providing scanf/printf like
     21    interface that opens and closes the file automatically.
     22 
     23    This kind of interface is especially useful for reading/writing values
     24    from/to pseudo filesystems like procfs or sysfs.
     25 
     26   */
     27 
     28 #ifndef SAFE_FILE_OPS
     29 #define SAFE_FILE_OPS
     30 
     31 #include "safe_file_ops_fn.h"
     32 
     33 #define FILE_SCANF(path, fmt, ...) \
     34 	file_scanf(__FILE__, __LINE__, \
     35 	           (path), (fmt), ## __VA_ARGS__)
     36 
     37 #define SAFE_FILE_SCANF(cleanup_fn, path, fmt, ...) \
     38 	safe_file_scanf(__FILE__, __LINE__, (cleanup_fn), \
     39 	                (path), (fmt), ## __VA_ARGS__)
     40 
     41 #define FILE_LINES_SCANF(cleanup_fn, path, fmt, ...) \
     42 	file_lines_scanf(__FILE__, __LINE__, (cleanup_fn), 0, \
     43 			(path), (fmt), ## __VA_ARGS__)
     44 
     45 #define SAFE_FILE_LINES_SCANF(cleanup_fn, path, fmt, ...) \
     46 	file_lines_scanf(__FILE__, __LINE__, (cleanup_fn), 1, \
     47 			(path), (fmt), ## __VA_ARGS__)
     48 
     49 #define FILE_PRINTF(path, fmt, ...) \
     50 	file_printf(__FILE__, __LINE__, \
     51 	            (path), (fmt), ## __VA_ARGS__)
     52 
     53 #define SAFE_FILE_PRINTF(cleanup_fn, path, fmt, ...) \
     54 	safe_file_printf(__FILE__, __LINE__, (cleanup_fn), \
     55 	                 (path), (fmt), ## __VA_ARGS__)
     56 
     57 #define SAFE_CP(cleanup_fn, src, dst) \
     58 	safe_cp(__FILE__, __LINE__, (cleanup_fn), (src), (dst))
     59 
     60 #define SAFE_TOUCH(cleanup_fn, pathname, mode, times) \
     61 	safe_touch(__FILE__, __LINE__, (cleanup_fn), \
     62 			(pathname), (mode), (times))
     63 
     64 #endif /* SAFE_FILE_OPS */
     65