path_utils  0.6.1
path_utils.h
1 /*
2  Authors:
3  John Dennis <jdennis.redhat.com>
4 
5  Copyright (C) 2009 Red Hat
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef PATH_UTILS_H
22 #define PATH_UTILS_H
23 
24 /*****************************************************************************/
25 /******************************** Documentation ******************************/
26 /*****************************************************************************/
27 
35 /*****************************************************************************/
36 /******************************* Include Files *******************************/
37 /*****************************************************************************/
38 
39 #include <stdbool.h>
40 #include <libintl.h>
41 #include <sys/param.h>
42 #include <sys/stat.h>
43 
44 /*****************************************************************************/
45 /*********************************** Defines *********************************/
46 /*****************************************************************************/
47 
53 #ifndef _
54 #define _(String) gettext(String)
55 #endif
56 
61 #ifndef SUCCESS
62 #define SUCCESS 0
63 #endif
64 
74 #define PATH_UTILS_ERROR_BASE -3000
75 #define PATH_UTILS_ERROR_LIMIT (PATH_UTILS_ERROR_BASE+20)
76 
81 #define IS_PATH_UTILS_ERROR(error) (((error) >= PATH_UTILS_ERROR_BASE) && ((error) < PATH_UTILS_ERROR_LIMIT))
82 
88 #define PATH_UTILS_ERROR_NOT_FULLY_NORMALIZED (PATH_UTILS_ERROR_BASE + 1)
89 
94 /*****************************************************************************/
95 /******************************* Type Definitions ****************************/
96 /*****************************************************************************/
97 
98 /*****************************************************************************/
99 /************************* External Global Variables ***********************/
100 /*****************************************************************************/
101 
102 /*****************************************************************************/
103 /**************************** Exported Functions ***************************/
104 /*****************************************************************************/
105 
117 const char *path_utils_error_string(int error);
118 
135 int get_basename(char *base_name, size_t base_name_size, const char *path);
136 
156 int get_dirname(char *dir_path, size_t dir_path_size, const char *path);
157 
178 int get_directory_and_base_name(char *dir_path, size_t dir_path_size,
179  char *base_name, size_t base_name_size,
180  const char *path);
181 
188 bool is_absolute_path(const char *path);
189 
204 int path_concat(char *path, size_t path_size, const char *head, const char *tail);
205 
218 int make_path_absolute(char *absolute_path, size_t absolute_path_size, const char *path);
219 
268 char **split_path(const char *path, int *count);
269 
310 int normalize_path(char *normalized_path, size_t normalized_path_size, const char *path);
311 
330 int common_path_prefix(char *common_path,
331  size_t common_path_size,
332  int *common_count,
333  const char *path1, const char *path2);
334 
335 
342 int make_normalized_absolute_path(char *result_path, size_t result_path_size, const char *path);
343 
359 int find_existing_directory_ancestor(char *ancestor, size_t ancestor_size, const char *path);
360 
375 typedef bool (*directory_list_callback_t)(const char *directory, const char *base_name,
376  const char *path, struct stat *info,
377  void *user_data);
398 int directory_list(const char *path, bool recursive,
399  directory_list_callback_t callback, void *user_data);
400 
424 bool is_ancestor_path(const char *ancestor, const char *path);
425 
430 #endif /* PATH_UTILS_H */
int make_normalized_absolute_path(char *result_path, size_t result_path_size, const char *path)
Make the input path absolute if it's not already, then normalize it.
Definition: path_utils.c:511
int get_basename(char *base_name, size_t base_name_size, const char *path)
Get the basename component of a path.
Definition: path_utils.c:111
char ** split_path(const char *path, int *count)
Split a file system path into individual components.
Definition: path_utils.c:305
int make_path_absolute(char *absolute_path, size_t absolute_path_size, const char *path)
Convert a path into absolute.
Definition: path_utils.c:260
bool is_ancestor_path(const char *ancestor, const char *path)
Tell if one path is ancestor of another.
Definition: path_utils.c:610
int directory_list(const char *path, bool recursive, directory_list_callback_t callback, void *user_data)
Walk a directory.
Definition: path_utils.c:552
int normalize_path(char *normalized_path, size_t normalized_path_size, const char *path)
Normalizes a path.
Definition: path_utils.c:371
int find_existing_directory_ancestor(char *ancestor, size_t ancestor_size, const char *path)
Definition: path_utils.c:523
int get_dirname(char *dir_path, size_t dir_path_size, const char *path)
Copy the directory components of a path.
Definition: path_utils.c:132
const char * path_utils_error_string(int error)
Given an error code return the string description.
Definition: path_utils.c:77
int common_path_prefix(char *common_path, size_t common_path_size, int *common_count, const char *path1, const char *path2)
Find the common prefix between two paths.
Definition: path_utils.c:447
bool(* directory_list_callback_t)(const char *directory, const char *base_name, const char *path, struct stat *info, void *user_data)
callback for the directory_list() function
Definition: path_utils.h:375
int get_directory_and_base_name(char *dir_path, size_t dir_path_size, char *base_name, size_t base_name_size, const char *path)
Get the basaname and directory components of a path.
Definition: path_utils.c:153
int path_concat(char *path, size_t path_size, const char *head, const char *tail)
Concatenate two components of a path.
Definition: path_utils.c:193
bool is_absolute_path(const char *path)
Tell if path is absolute or relative.
Definition: path_utils.c:187