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