doc
c_path.h
Go to the documentation of this file.
1 /*
2  * cynapses libc functions
3  *
4  * Copyright (c) 2007-2008 by Andreas Schneider <mail@cynapses.org>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * vim: ft=c.doxygen ts=2 sw=2 et cindent
21  */
22 
23 /**
24  * @file c_path.h
25  *
26  * @brief Interface of the cynapses libc path functions
27  *
28  * @defgroup cynPathInternals cynapses libc path functions
29  * @ingroup cynLibraryAPI
30  *
31  * @{
32  */
33 
34 #ifndef _C_PATH_H
35 #define _C_PATH_H
36 
37 #include "c_macro.h"
38 
39 /**
40  * @brief Parse directory component.
41  *
42  * dirname breaks a null-terminated pathname string into a directory component.
43  * In the usual case, c_dirname() returns the string up to, but not including,
44  * the final '/'. Trailing '/' characters are not counted as part of the
45  * pathname. The caller must free the memory.
46  *
47  * @param path The path to parse.
48  *
49  * @return The dirname of path or NULL if we can't allocate memory. If path
50  * does not contain a slash, c_dirname() returns the string ".". If
51  * path is the string "/", it returns the string "/". If path is
52  * NULL or an empty string, "." is returned.
53  */
54 char *c_dirname(const char *path);
55 
56 /**
57  * @brief basename - parse filename component.
58  *
59  * basename breaks a null-terminated pathname string into a filename component.
60  * c_basename() returns the component following the final '/'. Trailing '/'
61  * characters are not counted as part of the pathname.
62  *
63  * @param path The path to parse.
64  *
65  * @return The filename of path or NULL if we can't allocate memory. If path
66  * is a the string "/", basename returns the string "/". If path is
67  * NULL or an empty string, "." is returned.
68  */
69 char *c_basename (const char *path);
70 
71 /**
72  * @brief Make a temporary filename.
73  *
74  * @param template Template to replace. The last six characters of template
75  * must be XXXXXX and these are replaced with a string that
76  * makes the filename more or less unique. Since it will be
77  * modified, template must not be a string constant, but
78  * should be declared as a character array.
79  *
80  * @return 0 on succes, < 0 on error with errno set.
81  */
82 int c_tmpname(char *template);
83 
84 /**
85  * @brief parse a uri and split it into components.
86  *
87  * parse_uri parses an uri in the format
88  *
89  * [<scheme>:][//[<user>[:<password>]@]<host>[:<port>]]/[<path>]
90  *
91  * into its compoments. If you only want a special component,
92  * pass NULL for all other components. All components will be allocated if they have
93  * been found.
94  *
95  * @param uri The uri to parse.
96  * @param scheme String for the scheme component
97  * @param user String for the username component
98  * @param passwd String for the password component
99  * @param host String for the password component
100  * @param port Integer for the port
101  * @param path String for the path component with a leading slash.
102  *
103  * @return 0 on success, < 0 on error.
104  */
105 int c_parse_uri(const char *uri, char **scheme, char **user, char **passwd,
106  char **host, unsigned int *port, char **path);
107 
108 /**
109  * @brief Parts of a path.
110  *
111  * @param directory '\0' terminated path including the final '/'
112  *
113  * @param filename '\0' terminated string
114  *
115  * @param extension '\0' terminated string
116  *
117  */
118 typedef struct
119 {
120  char * directory;
121  char * filename;
122  char * extension;
123 } C_PATHINFO;
124 
125 /**
126  * @brief Extracting directory, filename and extension from a path.
127  *
128  * @param pathSrc The path to parse.
129  *
130  * @return Returns a C_PATHINFO structure that should be freed using SAFE_FREE().
131  */
132 C_PATHINFO * c_split_path(const char* pathSrc);
133 
134 
135 /**
136  * }@
137  */
138 #endif /* _C_PATH_H */