ECP-VELOC Components
User documentation for all components
spath.h
Go to the documentation of this file.
1 #ifndef SPATH_H
2 #define SPATH_H
3 
4 #include <stdarg.h>
5 #include <sys/types.h>
6 
7 /* enable C++ codes to include this header directly */
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 #define SPATH_SUCCESS (0)
13 #define SPATH_FAILURE (1)
14 
15 #define SPATH_VERSION "0.1.0"
16 
17 /* TODO: for formatted strings, use special %| character (or something
18  * similar) to denote directories in portable way */
19 
44 /********************************************************/
46 struct spath_elem_struct;
48 
50 typedef struct spath_elem_struct {
51  char* component; /* pointer to strdup'd component string */
52  size_t chars; /* number of chars in component */
53  struct spath_elem_struct* next; /* pointer to next element */
54  struct spath_elem_struct* prev; /* pointer to previous element */
55 } spath_elem;
56 
58 typedef struct spath_struct {
59  int components; /* number of components in path */
60  size_t chars; /* number of chars in path */
61  spath_elem* head; /* pointer to first element */
62  spath_elem* tail; /* pointer to last element */
63 } spath;
65 
66 /********************************************************/
68 
70 spath* spath_new(void);
71 
73 spath* spath_from_str(const char* str);
74 
76 spath* spath_from_strf(const char* format, ...);
77 
79 spath* spath_dup(const spath* path);
80 
82 int spath_delete(spath** ptr_path);
84 
85 /********************************************************/
87 
90 int spath_is_null(const spath* path);
91 
93 int spath_components(const spath* path);
94 
97 size_t spath_strlen(const spath* path);
98 
101 size_t spath_strcpy(char* buf, size_t n, const spath* path);
102 
105 char* spath_strdup(const spath* path);
107 
108 /********************************************************/
110 
117 int spath_insert(spath* path1, int offset, const spath* ptr_path2);
118 
120 int spath_prepend(spath* path1, const spath* ptr_path2);
121 
123 int spath_append(spath* path1, const spath* ptr_path2);
124 
130 int spath_insert_str(spath* path, int offset, const char* str);
131 
133 int spath_prepend_str(spath* path, const char* str);
134 
136 int spath_append_str(spath* path, const char* str);
137 
143 int spath_insert_strf(spath* path, int offset, const char* format, ...);
144 
146 int spath_prepend_strf(spath* path, const char* format, ...);
147 
149 int spath_append_strf(spath* path, const char* format, ...);
151 
152 /********************************************************/
154 
159 int spath_slice(spath* path, int offset, int length);
160 
162 int spath_dirname(spath* path);
163 
165 int spath_basename(spath* path);
166 
170 spath* spath_sub(spath* path, int offset, int length);
171 
174 spath* spath_cut(spath* path, int offset);
176 
177 /********************************************************/
179 
182 spath* spath_cwd(void);
183 
185 int spath_realpath(spath* path);
186 
188 int spath_reduce(spath* path);
189 
192 char* spath_strdup_reduce_str(const char* str);
193 
195 int spath_is_absolute(const spath* path);
196 
198 int spath_is_child(const spath* parent, const spath* child);
199 
201 spath* spath_relative(const spath* src, const spath* dst);
203 
204 /* enable C++ codes to include this header directly */
205 #ifdef __cplusplus
206 } /* extern "C" */
207 #endif
208 
209 #endif /* SPATH_H */
spath_sub
spath * spath_sub(spath *path, int offset, int length)
spath_elem_struct::next
struct spath_elem_struct * next
Definition: spath.h:53
spath_cwd
spath * spath_cwd(void)
spath_is_absolute
int spath_is_absolute(const spath *path)
spath_reduce
int spath_reduce(spath *path)
spath_prepend
int spath_prepend(spath *path1, const spath *ptr_path2)
spath_elem_struct::chars
size_t chars
Definition: spath.h:52
spath_struct::head
spath_elem * head
Definition: spath.h:61
spath_new
spath * spath_new(void)
spath_strlen
size_t spath_strlen(const spath *path)
spath_from_strf
spath * spath_from_strf(const char *format,...)
spath_append
int spath_append(spath *path1, const spath *ptr_path2)
spath_realpath
int spath_realpath(spath *path)
spath_insert_str
int spath_insert_str(spath *path, int offset, const char *str)
spath_strcpy
size_t spath_strcpy(char *buf, size_t n, const spath *path)
spath_dirname
int spath_dirname(spath *path)
spath_basename
int spath_basename(spath *path)
spath_elem_struct::prev
struct spath_elem_struct * prev
Definition: spath.h:54
spath_delete
int spath_delete(spath **ptr_path)
spath_elem_struct::component
char * component
Definition: spath.h:51
spath_struct::tail
spath_elem * tail
Definition: spath.h:62
spath_prepend_str
int spath_prepend_str(spath *path, const char *str)
spath_append_strf
int spath_append_strf(spath *path, const char *format,...)
spath_relative
spath * spath_relative(const spath *src, const spath *dst)
spath_prepend_strf
int spath_prepend_strf(spath *path, const char *format,...)
spath_slice
int spath_slice(spath *path, int offset, int length)
spath_append_str
int spath_append_str(spath *path, const char *str)
spath_insert
int spath_insert(spath *path1, int offset, const spath *ptr_path2)
spath_struct::chars
size_t chars
Definition: spath.h:60
spath_strdup
char * spath_strdup(const spath *path)
spath_from_str
spath * spath_from_str(const char *str)
spath_is_child
int spath_is_child(const spath *parent, const spath *child)
spath_dup
spath * spath_dup(const spath *path)
spath_components
int spath_components(const spath *path)
spath_strdup_reduce_str
char * spath_strdup_reduce_str(const char *str)
spath_struct
Definition: spath.h:58
spath_is_null
int spath_is_null(const spath *path)
spath_struct::components
int components
Definition: spath.h:59
spath_insert_strf
int spath_insert_strf(spath *path, int offset, const char *format,...)
spath_elem_struct
Definition: spath.h:50
spath_cut
spath * spath_cut(spath *path, int offset)