00001 /** 00002 * @file op_file.h 00003 * Useful file management helpers 00004 * 00005 * @remark Copyright 2002 OProfile authors 00006 * @remark Read the file COPYING 00007 * 00008 * @author John Levon 00009 * @author Philippe Elie 00010 */ 00011 00012 #ifndef OP_FILE_H 00013 #define OP_FILE_H 00014 00015 #ifdef __cplusplus 00016 extern "C" { 00017 #endif 00018 00019 #include <sys/types.h> 00020 00021 /** 00022 * op_file_readable - is a file readable 00023 * @param file file name 00024 * 00025 * Return true if the given file is readable and regular. 00026 * 00027 * Beware of race conditions ! 00028 */ 00029 int op_file_readable(char const * file); 00030 00031 /** 00032 * op_get_mtime - get mtime of file 00033 * @param file file name 00034 * 00035 * Returns the mtime of the given file or 0 on failure 00036 */ 00037 time_t op_get_mtime(char const * file); 00038 00039 /** 00040 * create_dir - create a directory 00041 * @param dir the directory name to create 00042 * 00043 * Returns 0 on success. 00044 */ 00045 int create_dir(char const * dir); 00046 00047 00048 /** 00049 * create_path - create a path 00050 * @param path the path to create 00051 * 00052 * create directory for each dir components in path 00053 * the last path component is not considered as a directory 00054 * but as a filename 00055 * 00056 * Returns 0 on success. 00057 */ 00058 int create_path(char const * path); 00059 00060 /** 00061 * Clients of get_matching_pathnames must provide their own implementation 00062 * of get_pathname_callback. 00063 */ 00064 typedef void (*get_pathname_callback)(char const * pathname, void * name_list); 00065 00066 /* This enum is intended solely for the use of get_matching_pathnames(), 00067 * bit 0 is reserved for internal use..*/ 00068 enum recursion_type { 00069 NO_RECURSION = 2, 00070 MATCH_ANY_ENTRY_RECURSION = 4, 00071 MATCH_DIR_ONLY_RECURSION = 8, 00072 }; 00073 /** 00074 * @param name_list where to store result 00075 * @param get_pathname_callback client-provided callback function 00076 * @param base_dir directory from where lookup starts 00077 * @param filter a pathname filter 00078 * @param recursion recursion_type -- see above enum and following description: 00079 * NO_RECURSION: Find matching files from passed base_dir and call 00080 * get_pathname_callback to add entry to name_list to be returned. 00081 * MATCH_ANY_ENTRY_RECURSION: Starting at base_dir, for each entry in the 00082 * dir that matches the filter: if entry is of type 'dir', recurse; 00083 * else call get_pathname_callback to add entry to name_list to be 00084 * returned. 00085 * MATCH_DIR_ONLY_RECURSION: Starting at base_dir, if an entry in the 00086 * dir is of type 'dir' and its complete pathname contains a match to 00087 * the filter, call get_pathname_callback to add entry to name_list to 00088 * be returned; else recurse. 00089 * 00090 * Returns 0 on success. 00091 * 00092 * Return a list of pathnames under base_dir, filtered by filter and optionally 00093 * looking in sub-directory. See description above of the recursion_type 00094 * parameter for more details. 00095 * NOTE: For C clients: Your implementation of the get_pathname_callback 00096 * function will probably dynamically allocate storage for elements 00097 * added to name_list. If so, remember to free that memory when it's 00098 * no longer needed. 00099 */ 00100 int get_matching_pathnames(void * name_list, get_pathname_callback, 00101 char const * base_dir, char const * filter, 00102 enum recursion_type recursion); 00103 00104 00105 #ifdef __cplusplus 00106 } 00107 #endif 00108 00109 #endif /* OP_FILE_H */
1.6.1