path_utils
0.1.3
|
00001 /* 00002 Authors: 00003 John Dennis <jdennis.redhat.com> 00004 00005 Copyright (C) 2009 Red Hat 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU Lesser General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. 00019 */ 00020 00021 #ifndef PATH_UTILS_H 00022 #define PATH_UTILS_H 00023 00024 /*****************************************************************************/ 00025 /******************************** Documentation ******************************/ 00026 /*****************************************************************************/ 00027 00035 /*****************************************************************************/ 00036 /******************************* Include Files *******************************/ 00037 /*****************************************************************************/ 00038 00039 #include <stdbool.h> 00040 #include <libintl.h> 00041 #include <sys/param.h> 00042 #include <sys/stat.h> 00043 00044 /*****************************************************************************/ 00045 /*********************************** Defines *********************************/ 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 /******************************* Type Definitions ****************************/ 00096 /*****************************************************************************/ 00097 00098 /*****************************************************************************/ 00099 /************************* External Global Variables ***********************/ 00100 /*****************************************************************************/ 00101 00102 /*****************************************************************************/ 00103 /**************************** Exported Functions ***************************/ 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 00204 int path_concat(char *path, size_t path_size, const char *head, const char *tail); 00205 00218 int make_path_absolute(char *absolute_path, size_t absolute_path_size, const char *path); 00219 00268 char **split_path(const char *path, int *count); 00269 00310 int normalize_path(char *normalized_path, size_t normalized_path_size, const char *path); 00311 00330 int common_path_prefix(char *common_path, 00331 size_t common_path_size, 00332 int *common_count, 00333 const char *path1, const char *path2); 00334 00335 00342 int make_normalized_absolute_path(char *result_path, size_t result_path_size, const char *path); 00343 00359 int find_existing_directory_ancestor(char *ancestor, size_t ancestor_size, const char *path); 00360 00375 typedef bool (*directory_list_callback_t)(const char *directory, const char *base_name, 00376 const char *path, struct stat *info, 00377 void *user_data); 00398 int directory_list(const char *path, bool recursive, 00399 directory_list_callback_t callback, void *user_data); 00400 00424 bool is_ancestor_path(const char *ancestor, const char *path); 00425 00430 #endif /* PATH_UTILS_H */