libsqsh v1.5.1
Loading...
Searching...
No Matches
sqsh_tree.h
Go to the documentation of this file.
1/******************************************************************************
2 * *
3 * Copyright (c) 2023-2024, Enno Boland <g@s01.de> *
4 * *
5 * Redistribution and use in source and binary forms, with or without *
6 * modification, are permitted provided that the following conditions are *
7 * met: *
8 * *
9 * * Redistributions of source code must retain the above copyright notice, *
10 * this list of conditions and the following disclaimer. *
11 * * Redistributions in binary form must reproduce the above copyright *
12 * notice, this list of conditions and the following disclaimer in the *
13 * documentation and/or other materials provided with the distribution. *
14 * *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS *
16 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, *
17 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR *
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR *
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
23 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
24 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
26 * *
27 ******************************************************************************/
28
34#ifndef SQSH_TREE_H
35#define SQSH_TREE_H
36
37#include "sqsh_common.h"
38
39#include "sqsh_file.h"
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44
45struct SqshArchive;
46
47/***************************************
48 * tree/path_resolver.c
49 */
50
51struct SqshPathResolver;
52
62struct SqshPathResolver *
63sqsh_path_resolver_new(struct SqshArchive *archive, int *err);
64
74
88sqsh_path_resolver_next(struct SqshPathResolver *walker, int *err);
89
98enum SqshFileType
100
110const char *sqsh_path_resolver_name(const struct SqshPathResolver *walker);
111
120uint16_t sqsh_path_resolver_name_size(const struct SqshPathResolver *walker);
121
134SQSH_NO_UNUSED char *
136
146
158 struct SqshPathResolver *walker, const char *name,
159 const size_t name_size);
160
170
180
191sqsh_path_resolver_open_file(const struct SqshPathResolver *walker, int *err);
192
201uint32_t sqsh_path_resolver_dir_inode(const struct SqshPathResolver *walker);
202
211uint64_t sqsh_path_resolver_inode_ref(const struct SqshPathResolver *walker);
212
227 struct SqshPathResolver *walker, const char *path,
228 bool follow_symlinks);
229
239
240/***************************************
241 * tree/walker.c
242 */
243
244struct SqshTreeWalker;
245
256__attribute__((deprecated("Since 1.2.0. Use sqsh_path_resolver_new() "
257 "instead."))) struct SqshTreeWalker *
258sqsh_tree_walker_new(struct SqshArchive *archive, int *err);
259
269__attribute__((deprecated("Since 1.2.0. Use sqsh_path_resolver_up() "
270 "instead."))) SQSH_NO_UNUSED int
272
285__attribute__((deprecated("Since 1.2.0. Use sqsh_path_resolver_next() "
286 "instead."))) SQSH_NO_UNUSED int
288
298__attribute__((deprecated("Since 1.2.0. Use sqsh_path_resolver_type() "
299 "instead."))) enum SqshFileType
301
312__attribute__((deprecated("Since 1.2.0. Use sqsh_path_resolver_name() "
313 "instead."))) const char *
315
325__attribute__((deprecated("Since 1.2.0. Use sqsh_path_resolver_name_size() "
326 "instead."))) uint16_t
328
342__attribute__((deprecated("Since 1.2.0. Use sqsh_path_resolver_name_dup() "
343 "instead."))) SQSH_NO_UNUSED char *
345
355__attribute__((deprecated("Since 1.2.0. Use sqsh_path_resolver_revert() "
356 "instead."))) SQSH_NO_UNUSED int
358
370__attribute__((deprecated("Since 1.2.0. Use sqsh_path_resolver_lookup() "
371 "instead."))) SQSH_NO_UNUSED int
373 struct SqshTreeWalker *walker, const char *name,
374 const size_t name_size);
375
385__attribute__((deprecated("Since 1.2.0. Use sqsh_path_resolver_down() "
386 "instead."))) SQSH_NO_UNUSED int
388
398__attribute__((deprecated("Since 1.2.0. Use sqsh_path_resolver_to_root() "
399 "instead."))) SQSH_NO_UNUSED int
401
412__attribute__((deprecated("Since 1.2.0. Use sqsh_path_resolver_open_file() "
413 "instead."))) SQSH_NO_UNUSED struct SqshFile *
414sqsh_tree_walker_open_file(const struct SqshTreeWalker *walker, int *err);
415
430__attribute__((deprecated("Since 1.2.0. Use sqsh_path_resolver_resolve() "
431 "instead."))) SQSH_NO_UNUSED int
433 struct SqshTreeWalker *walker, const char *path, bool follow_symlinks);
434
444__attribute__((deprecated("Since 1.2.0. Use sqsh_path_resolver_free() "
445 "instead."))) int
447
448/***************************************
449 * tree/traversal.c
450 */
451
480
481struct SqshTreeTraversal;
482
499struct SqshTreeTraversal *
500sqsh_tree_traversal_new(const struct SqshFile *file, int *err);
501
510 struct SqshTreeTraversal *traversal, size_t max_depth);
511
523sqsh_tree_traversal_next(struct SqshTreeTraversal *traversal, int *err);
524
533enum SqshFileType
535
546
561 const struct SqshTreeTraversal *traversal, size_t *len);
562
577char *sqsh_tree_traversal_path_dup(const struct SqshTreeTraversal *traversal);
578
591SQSH_NO_UNUSED char *
593
602size_t sqsh_tree_traversal_depth(const struct SqshTreeTraversal *traversal);
603
629 const struct SqshTreeTraversal *traversal, size_t *len,
630 sqsh_index_t index);
631
640const struct SqshDirectoryIterator *
642
653 const struct SqshTreeTraversal *traversal, int *err);
654
663
664#ifdef __cplusplus
665}
666#endif
667#endif // SQSH_TREE_H
#define SQSH_NO_UNUSED
Warn if return value is unused.
Definition sqsh_common.h:59
size_t sqsh_index_t
typedef used for indexing
Definition sqsh_common.h:69
SqshFileType
enum that represents the file type.
Definition sqsh_file.h:315
const struct SqshDirectoryIterator * sqsh_tree_traversal_iterator(const struct SqshTreeTraversal *traversal)
Gets the underlying directory iterator pointing to the current entry.
SqshTreeTraversalState
The state of the tree traversal.
Definition sqsh_tree.h:455
@ SQSH_TREE_TRAVERSAL_STATE_INIT
Definition sqsh_tree.h:459
@ SQSH_TREE_TRAVERSAL_STATE_FILE
Definition sqsh_tree.h:466
@ SQSH_TREE_TRAVERSAL_STATE_DIRECTORY_BEGIN
Definition sqsh_tree.h:473
@ SQSH_TREE_TRAVERSAL_STATE_DIRECTORY_END
Definition sqsh_tree.h:478
A directory iterator.
The Inode context.
Resolves paths.
const char * sqsh_path_resolver_name(const struct SqshPathResolver *walker)
Returns the name of the current entry. This entry is not zero terminated.
uint64_t sqsh_path_resolver_inode_ref(const struct SqshPathResolver *walker)
Returns the inode reference of the current entry.
struct SqshPathResolver * sqsh_path_resolver_new(struct SqshArchive *archive, int *err)
Creates a new SqshPathResolver object at the root inode.
SQSH_NO_UNUSED char * sqsh_path_resolver_name_dup(const struct SqshPathResolver *walker)
creates a heap allocated copy of the name of the current entry.
SQSH_NO_UNUSED int sqsh_path_resolver_resolve(struct SqshPathResolver *walker, const char *path, bool follow_symlinks)
Resolve a path with the tree walker.
uint32_t sqsh_path_resolver_dir_inode(const struct SqshPathResolver *walker)
Returns the inode of the current working directory.
enum SqshFileType sqsh_path_resolver_type(const struct SqshPathResolver *walker)
Returns the inode type of the current entry.
SQSH_NO_UNUSED int sqsh_path_resolver_up(struct SqshPathResolver *walker)
Moves the walker one level up.
SQSH_NO_UNUSED int sqsh_path_resolver_lookup(struct SqshPathResolver *walker, const char *name, const size_t name_size)
Looks up an entry in the current directory.
SQSH_NO_UNUSED int sqsh_path_resolver_down(struct SqshPathResolver *walker)
Lets the walker enter the current entry.
SQSH_NO_UNUSED int sqsh_path_resolver_to_root(struct SqshPathResolver *walker)
Moves the walker to the root directory.
SQSH_NO_UNUSED struct SqshFile * sqsh_path_resolver_open_file(const struct SqshPathResolver *walker, int *err)
Returns the inode of the current entry.
int sqsh_path_resolver_free(struct SqshPathResolver *reader)
Cleans up resources used by a SqshPathResolver struct.
SQSH_NO_UNUSED int sqsh_path_resolver_revert(struct SqshPathResolver *walker)
reverts the walker to the begining of the current directory.
uint16_t sqsh_path_resolver_name_size(const struct SqshPathResolver *walker)
Returns the size of the name of the current entry.
SQSH_NO_UNUSED bool sqsh_path_resolver_next(struct SqshPathResolver *walker, int *err)
Moves the walker to the next entry int the current directory.
A walker over the contents of a file.
SQSH_NO_UNUSED char * sqsh_tree_traversal_name_dup(const struct SqshTreeTraversal *traversal)
creates a heap allocated copy of the name of the current entry.
enum SqshTreeTraversalState sqsh_tree_traversal_state(const struct SqshTreeTraversal *traversal)
returns the state of the traversal.
SQSH_NO_UNUSED bool sqsh_tree_traversal_next(struct SqshTreeTraversal *traversal, int *err)
Moves the traversal to the next entry int the current directory.
char * sqsh_tree_traversal_path_dup(const struct SqshTreeTraversal *traversal)
Creates a heap allocated copy of the path to the current entry.
int sqsh_tree_traversal_free(struct SqshTreeTraversal *traversal)
void sqsh_tree_traversal_set_max_depth(struct SqshTreeTraversal *traversal, size_t max_depth)
Sets the maximum depth of the traversal.
const char * sqsh_tree_traversal_name(const struct SqshTreeTraversal *traversal, size_t *len)
Returns the name of the current entry.
struct SqshTreeTraversal * sqsh_tree_traversal_new(const struct SqshFile *file, int *err)
Creates a new SqshTreeTraversal object rooted at the specified inode.
const char * sqsh_tree_traversal_path_segment(const struct SqshTreeTraversal *traversal, size_t *len, sqsh_index_t index)
Get a segment of the path of the current entry.
enum SqshFileType sqsh_tree_traversal_type(const struct SqshTreeTraversal *traversal)
Returns the inode type of the current entry.
size_t sqsh_tree_traversal_depth(const struct SqshTreeTraversal *traversal)
Returns the path segment at a given index.
SQSH_NO_UNUSED struct SqshFile * sqsh_tree_traversal_open_file(const struct SqshTreeTraversal *traversal, int *err)
Returns the inode of the current entry.
A walker over the contents of a file.
SQSH_NO_UNUSED struct SqshFile * sqsh_tree_walker_open_file(const struct SqshTreeWalker *walker, int *err)
Returns the inode of the current entry.
SQSH_NO_UNUSED int sqsh_tree_walker_up(struct SqshTreeWalker *walker)
Moves the walker one level up.
uint16_t sqsh_tree_walker_name_size(const struct SqshTreeWalker *walker)
Returns the size of the name of the current entry.
enum SqshFileType sqsh_tree_walker_type(const struct SqshTreeWalker *walker)
Returns the inode type of the current entry.
SQSH_NO_UNUSED int sqsh_tree_walker_resolve(struct SqshTreeWalker *walker, const char *path, bool follow_symlinks)
Resolve a path with the tree walker.
struct SqshTreeWalker * sqsh_tree_walker_new(struct SqshArchive *archive, int *err)
Creates a new SqshTreeWalker object at the root inode.
SQSH_NO_UNUSED int sqsh_tree_walker_to_root(struct SqshTreeWalker *walker)
Moves the walker to the root directory.
SQSH_NO_UNUSED int sqsh_tree_walker_next(struct SqshTreeWalker *walker)
Moves the walker to the next entry int the current directory.
const char * sqsh_tree_walker_name(const struct SqshTreeWalker *walker)
Returns the name of the current entry. This entry is not zero terminated.
SQSH_NO_UNUSED int sqsh_tree_walker_lookup(struct SqshTreeWalker *walker, const char *name, const size_t name_size)
Looks up an entry in the current directory.
SQSH_NO_UNUSED int sqsh_tree_walker_down(struct SqshTreeWalker *walker)
Lets the walker enter the current entry.
SQSH_NO_UNUSED char * sqsh_tree_walker_name_dup(const struct SqshTreeWalker *walker)
creates a heap allocated copy of the name of the current entry.
SQSH_NO_UNUSED int sqsh_tree_walker_revert(struct SqshTreeWalker *walker)
reverts the walker to the begining of the current directory.
int sqsh_tree_walker_free(struct SqshTreeWalker *reader)
Cleans up resources used by a SqshTreeWalker struct.