path_utils 0.6.2
Loading...
Searching...
No Matches
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
117const char *path_utils_error_string(int error);
118
135int get_basename(char *base_name, size_t base_name_size, const char *path);
136
156int get_dirname(char *dir_path, size_t dir_path_size, const char *path);
157
178int 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
188bool is_absolute_path(const char *path);
189
204int path_concat(char *path, size_t path_size, const char *head, const char *tail);
205
218int make_path_absolute(char *absolute_path, size_t absolute_path_size, const char *path);
219
268char **split_path(const char *path, int *count);
269
310int normalize_path(char *normalized_path, size_t normalized_path_size, const char *path);
311
330int 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
342int make_normalized_absolute_path(char *result_path, size_t result_path_size, const char *path);
343
359int find_existing_directory_ancestor(char *ancestor, size_t ancestor_size, const char *path);
360
375typedef bool (*directory_list_callback_t)(const char *directory, const char *base_name,
376 const char *path, struct stat *info,
377 void *user_data);
398int directory_list(const char *path, bool recursive,
399 directory_list_callback_t callback, void *user_data);
400
424bool 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:515
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 path_concat(char *path, size_t path_size, const char *head, const char *tail)
Concatenate two components of a path.
Definition path_utils.c:197
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:155
int make_path_absolute(char *absolute_path, size_t absolute_path_size, const char *path)
Convert a path into absolute.
Definition path_utils.c:264
bool is_ancestor_path(const char *ancestor, const char *path)
Tell if one path is ancestor of another.
Definition path_utils.c:615
int directory_list(const char *path, bool recursive, directory_list_callback_t callback, void *user_data)
Walk a directory.
Definition path_utils.c:557
int find_existing_directory_ancestor(char *ancestor, size_t ancestor_size, const char *path)
Definition path_utils.c:527
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:451
const char * path_utils_error_string(int error)
Given an error code return the string description.
Definition path_utils.c:77
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:133
char ** split_path(const char *path, int *count)
Split a file system path into individual components.
Definition path_utils.c:309
bool is_absolute_path(const char *path)
Tell if path is absolute or relative.
Definition path_utils.c:191
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
int normalize_path(char *normalized_path, size_t normalized_path_size, const char *path)
Normalizes a path.
Definition path_utils.c:375