00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef PATH_UTILS_H
00022 #define PATH_UTILS_H
00023
00024
00025
00026
00027
00035
00036
00037
00038
00039 #include <stdbool.h>
00040 #include <libintl.h>
00041 #include <sys/param.h>
00042 #include <sys/stat.h>
00043
00044
00045
00046
00047
00053 #ifndef _
00054 #define _(String) gettext(String)
00055 #endif
00056
00061 #ifndef SUCCESS
00062 #define SUCCESS 0
00063 #endif
00064
00074 #define PATH_UTILS_ERROR_BASE -3000
00075 #define PATH_UTILS_ERROR_LIMIT (PATH_UTILS_ERROR_BASE+20)
00076
00081 #define IS_PATH_UTILS_ERROR(error) (((error) >= PATH_UTILS_ERROR_BASE) && ((error) < PATH_UTILS_ERROR_LIMIT))
00082
00088 #define PATH_UTILS_ERROR_NOT_FULLY_NORMALIZED (PATH_UTILS_ERROR_BASE + 1)
00089
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00117 const char *path_utils_error_string(int error);
00118
00135 int get_basename(char *base_name, size_t base_name_size, const char *path);
00136
00156 int get_dirname(char *dir_path, size_t dir_path_size, const char *path);
00157
00178 int get_directory_and_base_name(char *dir_path, size_t dir_path_size,
00179 char *base_name, size_t base_name_size,
00180 const char *path);
00181
00188 bool is_absolute_path(const char *path);
00189
00203 int path_concat(char *path, size_t path_size, const char *head, const char *tail);
00204
00217 int make_path_absolute(char *absolute_path, size_t absolute_path_size, const char *path);
00218
00267 char **split_path(const char *path, int *count);
00268
00309 int normalize_path(char *normalized_path, size_t normalized_path_size, const char *path);
00310
00329 int common_path_prefix(char *common_path,
00330 size_t common_path_size,
00331 int *common_count,
00332 const char *path1, const char *path2);
00333
00334
00341 int make_normalized_absolute_path(char *result_path, size_t result_path_size, const char *path);
00342
00358 int find_existing_directory_ancestor(char *ancestor, size_t ancestor_size, const char *path);
00359
00374 typedef bool (*directory_list_callback_t)(const char *directory, const char *base_name,
00375 const char *path, struct stat *info,
00376 void *user_data);
00397 int directory_list(const char *path, bool recursive,
00398 directory_list_callback_t callback, void *user_data);
00399
00423 bool is_ancestor_path(const char *ancestor, const char *path);
00424
00429 #endif