op_file.c File Reference

Useful file management helpers. More...

#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <dirent.h>
#include <fnmatch.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <limits.h>
#include "op_file.h"
#include "op_libiberty.h"
Include dependency graph for op_file.c:


#define NO_MATCH   0
#define MATCH   1


int op_file_readable (char const *file)
 op_file_readable - is a file readable
time_t op_get_mtime (char const *file)
 op_get_mtime - get mtime of file
int create_dir (char const *dir)
 create_dir - create a directory
int create_path (char const *path)
 create_path - create a path
int get_matching_pathnames (void *name_list, get_pathname_callback getpathname, char const *base_dir, char const *filter, enum recursion_type recursion)

Detailed Description

Useful file management helpers.

Copyright 2002 OProfile authors
Read the file COPYING
John Levon
Philippe Elie

Define Documentation

#define MATCH   1

Referenced by get_matching_pathnames().

#define NO_MATCH   0

Referenced by get_matching_pathnames().

Function Documentation

int create_dir ( char const *  dir  ) 

create_dir - create a directory

dir the directory name to create

Returns 0 on success.

Referenced by check_and_create_config_dir(), create_path(), and op_open_agent().

int create_path ( char const *  path  ) 

create_path - create a path

path the path to create

create directory for each dir components in path the last path component is not considered as a directory but as a filename

Returns 0 on success.

References create_dir().

Referenced by opd_open_sample_file(), and operf_open_sample_file().

int get_matching_pathnames ( void *  name_list,
get_pathname_callback  ,
char const *  base_dir,
char const *  filter,
enum recursion_type  recursion 
name_list where to store result
get_pathname_callback client-provided callback function
base_dir directory from where lookup starts
filter a pathname filter
recursion recursion_type -- see above enum and following description: NO_RECURSION: Find matching files from passed base_dir and call get_pathname_callback to add entry to name_list to be returned. MATCH_ANY_ENTRY_RECURSION: Starting at base_dir, for each entry in the dir that matches the filter: if entry is of type 'dir', recurse; else call get_pathname_callback to add entry to name_list to be returned. MATCH_DIR_ONLY_RECURSION: Starting at base_dir, if an entry in the dir is of type 'dir' and its complete pathname contains a match to the filter, call get_pathname_callback to add entry to name_list to be returned; else recurse.

Returns 0 on success.

Return a list of pathnames under base_dir, filtered by filter and optionally looking in sub-directory. See description above of the recursion_type parameter for more details. NOTE: For C clients: Your implementation of the get_pathname_callback function will probably dynamically allocate storage for elements added to name_list. If so, remember to free that memory when it's no longer needed.


Referenced by create_file_list(), and get_matching_pathnames().

int op_file_readable ( char const *  file  ) 

op_file_readable - is a file readable

file file name

Return true if the given file is readable and regular.

Beware of race conditions !

Referenced by copy_file(), op_file_readable(), op_get_interface(), op_write_lock_file(), and oprof_start::oprof_start().

time_t op_get_mtime ( char const *  file  ) 

op_get_mtime - get mtime of file

file file name

Returns the mtime of the given file or 0 on failure

Referenced by check_mtime(), opd_open_sample_file(), and operf_open_sample_file().

Generated on 29 Jul 2013 for oprofile by  doxygen 1.6.1