libsqsh v1.5.1
Loading...
Searching...
No Matches
SqshTreeTraversal Struct Reference

A walker over the contents of a file. More...

#include <sqsh_tree_private.h>

Public Member Functions

struct SqshTreeTraversalsqsh_tree_traversal_new (const struct SqshFile *file, int *err)
 Creates a new SqshTreeTraversal object rooted at the specified inode.
 
void sqsh_tree_traversal_set_max_depth (struct SqshTreeTraversal *traversal, size_t max_depth)
 Sets the maximum depth 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.
 
enum SqshFileType sqsh_tree_traversal_type (const struct SqshTreeTraversal *traversal)
 Returns the inode type of the current entry.
 
enum SqshTreeTraversalState sqsh_tree_traversal_state (const struct SqshTreeTraversal *traversal)
 returns the state of the traversal.
 
const char * sqsh_tree_traversal_name (const struct SqshTreeTraversal *traversal, size_t *len)
 Returns the name of the current entry.
 
char * sqsh_tree_traversal_path_dup (const struct SqshTreeTraversal *traversal)
 Creates a heap allocated copy of the path to the current entry.
 
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.
 
size_t sqsh_tree_traversal_depth (const struct SqshTreeTraversal *traversal)
 Returns the path segment at a given index.
 
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.
 
SQSH_NO_UNUSED struct SqshFilesqsh_tree_traversal_open_file (const struct SqshTreeTraversal *traversal, int *err)
 Returns the inode of the current entry.
 
int sqsh_tree_traversal_free (struct SqshTreeTraversal *traversal)
 

Detailed Description

A walker over the contents of a file.

Definition at line 110 of file sqsh_tree_private.h.

Member Function Documentation

◆ sqsh_tree_traversal_depth()

size_t sqsh_tree_traversal_depth ( const struct SqshTreeTraversal * traversal)

Returns the path segment at a given index.

Parameters
[in,out]traversalThe traversal to use
Returns
the inode of the current entry.

◆ sqsh_tree_traversal_free()

int sqsh_tree_traversal_free ( struct SqshTreeTraversal * traversal)
Parameters
[in,out]traversalThe file traversal struct to clean up.
Returns
0 on success, less than 0 on error.

◆ sqsh_tree_traversal_name()

const char * sqsh_tree_traversal_name ( const struct SqshTreeTraversal * traversal,
size_t * len )

Returns the name of the current entry.

This entry is not zero terminated. The function will return an empty string for the uppermost object.

Parameters
[in]traversalThe traversal to use
[out]lenPointer to a size_t where the length of the name will be stored.
Returns
the name of the current entry.

◆ sqsh_tree_traversal_name_dup()

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.

The caller is responsible for calling free() on the returned pointer.

The returned string is 0 terminated.

Parameters
[in]traversalThe traversal to use
Returns
the name of the current entry.

◆ sqsh_tree_traversal_new()

struct SqshTreeTraversal * sqsh_tree_traversal_new ( const struct SqshFile * file,
int * err )

Creates a new SqshTreeTraversal object rooted at the specified inode.

The returned traversal iterator object borrows the passed file object. The returned traversal iterator object will visit all entries recursively located below the passed inode (which can be limited with sqsh_tree_traversal_set_max_depth). If the passed inode is not a directory, only the passed inode itself will be visited.

Parameters
[in]filethe base inode to start from.
[out]errPointer to an int where the error code will be stored.
Returns
a new tree traversal object.

◆ sqsh_tree_traversal_next()

SQSH_NO_UNUSED bool sqsh_tree_traversal_next ( struct SqshTreeTraversal * traversal,
int * err )

Moves the traversal to the next entry int the current directory.

Parameters
[in,out]traversalThe traversal to use
[out]errPointer to an int where the error code will be stored.
Returns
true if the traversal was moved to the next entry, false if the traversal has no more entries to move to or an error occurred.

◆ sqsh_tree_traversal_open_file()

SQSH_NO_UNUSED struct SqshFile * sqsh_tree_traversal_open_file ( const struct SqshTreeTraversal * traversal,
int * err )

Returns the inode of the current entry.

Parameters
[in,out]traversalThe traversal to use
[out]errPointer to an int where the error code will be
Returns
a newly allocated SqshFile for the current entry.

◆ sqsh_tree_traversal_path_dup()

char * sqsh_tree_traversal_path_dup ( const struct SqshTreeTraversal * traversal)

Creates a heap allocated copy of the path to the current entry.

The caller is responsible for calling free() on the returned pointer.

The returned string is 0 terminated.

Parameters
[in]traversalThe traversal to use
Returns
a newly heap allocated string containing the path to the current entry

◆ sqsh_tree_traversal_path_segment()

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.

A path segment is a part of the path that is separated by a path separator (/). The segments are indexed starting at 0, and there are depth segments in total (0 <= index < depth). The last segment is the name of the current entry.

The root of the traversal is considered at depth 0, and so has no path segments (or name).

If the traversal is rooted at /a/b, and the traversal iterator is pointing at /a/b/c/d.txt, the path segments will be [c, d.txt].

The returned pointer is not zero terminated.

Parameters
[in,out]traversalThe traversal to use
[out]lenPointer to a size_t where the length of the name will be stored.
[in]indexThe index of the path segment.
Returns
the inode of the current entry.

◆ sqsh_tree_traversal_set_max_depth()

void sqsh_tree_traversal_set_max_depth ( struct SqshTreeTraversal * traversal,
size_t max_depth )

Sets the maximum depth of the traversal.

Parameters
[in]traversalThe traversal to use
[in]max_depthThe maximum depth to traverse.

◆ sqsh_tree_traversal_state()

enum SqshTreeTraversalState sqsh_tree_traversal_state ( const struct SqshTreeTraversal * traversal)

returns the state of the traversal.

Parameters
[in]traversalThe traversal to use
Returns
The current state of the traversal.

◆ sqsh_tree_traversal_type()

enum SqshFileType sqsh_tree_traversal_type ( const struct SqshTreeTraversal * traversal)

Returns the inode type of the current entry.

Parameters
[in]traversalThe traversal to use
Returns
the inode type of the current entry.

The documentation for this struct was generated from the following files: