ECP-VELOC Components
User documentation for all components
Data Structures
spath.h File Reference

This file defines the data structure for a path, which is an double-linked list of elements, where each element contains a component (char string). More...

Detailed Description

functions to send/recv an spath object

Stores path as a linked list, breaking path at each directory marker and terminating NUL. Can append and insert paths or cut and slice them. Can initialize a path from a string and extract a path into a string. Path consists of a number of components indexed from 0.

Examples:

Definition in file spath.h.

Go to the source code of this file.

Data Structures

struct  spath_elem_struct
 
struct  spath_struct
 

Functions

Allocate and delete path objects
spath * spath_new (void)
 
spath * spath_from_str (const char *str)
 
spath * spath_from_strf (const char *format,...)
 
spath * spath_dup (const spath *path)
 
int spath_delete (spath **ptr_path)
 
get size and string functions
int spath_is_null (const spath *path)
 
int spath_components (const spath *path)
 
size_t spath_strlen (const spath *path)
 
size_t spath_strcpy (char *buf, size_t n, const spath *path)
 
char * spath_strdup (const spath *path)
 
insert, append, prepend functions
int spath_insert (spath *path1, int offset, const spath *ptr_path2)
 
int spath_prepend (spath *path1, const spath *ptr_path2)
 
int spath_append (spath *path1, const spath *ptr_path2)
 
int spath_insert_str (spath *path, int offset, const char *str)
 
int spath_prepend_str (spath *path, const char *str)
 
int spath_append_str (spath *path, const char *str)
 
int spath_insert_strf (spath *path, int offset, const char *format,...)
 
int spath_prepend_strf (spath *path, const char *format,...)
 
int spath_append_strf (spath *path, const char *format,...)
 
cut, slice, and subpath functions
int spath_slice (spath *path, int offset, int length)
 
int spath_dirname (spath *path)
 
int spath_basename (spath *path)
 
spath * spath_sub (spath *path, int offset, int length)
 
spath * spath_cut (spath *path, int offset)
 
simplify and resolve functions
spath * spath_cwd (void)
 
int spath_realpath (spath *path)
 
int spath_reduce (spath *path)
 
char * spath_strdup_reduce_str (const char *str)
 
int spath_is_absolute (const spath *path)
 
int spath_is_child (const spath *parent, const spath *child)
 
spath * spath_relative (const spath *src, const spath *dst)
 

Function Documentation

◆ spath_append()

int spath_append ( spath *  path1,
const spath *  ptr_path2 
)

appends path2 to path1

◆ spath_append_str()

int spath_append_str ( spath *  path,
const char *  str 
)

appends components in string to path

◆ spath_append_strf()

int spath_append_strf ( spath *  path,
const char *  format,
  ... 
)

adds new components to end of path using printf-like formatting

◆ spath_basename()

int spath_basename ( spath *  path)

only leaves last component of path

◆ spath_components()

int spath_components ( const spath *  path)

return number of components in path

◆ spath_cut()

spath* spath_cut ( spath *  path,
int  offset 
)

chops path at specified location and returns remainder as new path, offset can be negative to count from back of path

◆ spath_cwd()

spath* spath_cwd ( void  )

allocate a new path initialized with current working dir

◆ spath_delete()

int spath_delete ( spath **  ptr_path)

frees a path and sets path pointer to NULL

◆ spath_dirname()

int spath_dirname ( spath *  path)

drops last component from path

◆ spath_dup()

spath* spath_dup ( const spath *  path)

allocates and returns a copy of path

◆ spath_from_str()

spath* spath_from_str ( const char *  str)

allocates a path from string

◆ spath_from_strf()

spath* spath_from_strf ( const char *  format,
  ... 
)

allocates a path from formatted string

◆ spath_insert()

int spath_insert ( spath *  path1,
int  offset,
const spath *  ptr_path2 
)

inserts path2 so head element in path2 starts at specified offset in path1, e.g.,

  • 0 - before first element of path1
  • N-1 - before last element of path1
  • N - after last element of path1

◆ spath_insert_str()

int spath_insert_str ( spath *  path,
int  offset,
const char *  str 
)

inserts components in string so first component in string starts at specified offset in path, e.g.,

  • 0 - before first element of path
  • N-1 - before last element of path
  • N - after last element of path

◆ spath_insert_strf()

int spath_insert_strf ( spath *  path,
int  offset,
const char *  format,
  ... 
)

inserts components in string so first component in string starts at specified offset in path, e.g.,

  • 0 - before first element of path
  • N-1 - before last element of path
  • N - after last element of path

◆ spath_is_absolute()

int spath_is_absolute ( const spath *  path)

return 1 if path starts with an empty string, 0 otherwise

◆ spath_is_child()

int spath_is_child ( const spath *  parent,
const spath *  child 
)

return 1 if child is contained in tree starting at parent, 0 otherwise

◆ spath_is_null()

int spath_is_null ( const spath *  path)

returns 1 if path has 0 components, 0 otherwise

◆ spath_new()

spath* spath_new ( void  )

allocates a new path

◆ spath_prepend()

int spath_prepend ( spath *  path1,
const spath *  ptr_path2 
)

prepends path2 to path1

◆ spath_prepend_str()

int spath_prepend_str ( spath *  path,
const char *  str 
)

prepends components in string to path

◆ spath_prepend_strf()

int spath_prepend_strf ( spath *  path,
const char *  format,
  ... 
)

prepends components in string to path

◆ spath_realpath()

int spath_realpath ( spath *  path)

apply realpath to given path

◆ spath_reduce()

int spath_reduce ( spath *  path)

removes consecutive '/', '.', '..', and trailing '/'

◆ spath_relative()

spath* spath_relative ( const spath *  src,
const spath *  dst 
)

compute and return relative path from src to dst

◆ spath_slice()

int spath_slice ( spath *  path,
int  offset,
int  length 
)

keeps upto length components of path starting at specified location and discards the rest, offset can be negative to count from back, a negative length copies the remainder of the string

◆ spath_strcpy()

size_t spath_strcpy ( char *  buf,
size_t  n,
const spath *  path 
)

copy string into user buffer, abort if buffer is too small, return number of bytes written

◆ spath_strdup()

char* spath_strdup ( const spath *  path)

allocate memory and return path in string form, caller is responsible for freeing string with free()

◆ spath_strdup_reduce_str()

char* spath_strdup_reduce_str ( const char *  str)

creates path from string, calls reduce, calls path_strdup, and deletes path, caller must free returned string with free

◆ spath_strlen()

size_t spath_strlen ( const spath *  path)

return number of characters needed to store path (excludes terminating NUL)

◆ spath_sub()

spath* spath_sub ( spath *  path,
int  offset,
int  length 
)

copies upto length components of path starting at specified location and returns subpath as new path, offset can be negative to count from back, a negative length copies the remainder of the string