cuos/path.h: File path functions
[cuos: Interface to the Operating System]

Functions

cu_bool_t cuos_is_path_charr (char const *s, size_t len)
cu_bool_t cuos_is_path_cstr (char const *s)
cu_bool_t cuos_is_path_str (cu_str_t str)
cu_str_t cuos_path_from_charr (char const *s, size_t len)
cu_str_t cuos_path_from_cstr (char const *s)
cu_str_t cuos_path_from_str (cu_str_t str)
cu_bool_t cuos_path_is_abs (cu_str_t path)
cu_bool_t cuos_is_pathcomp_str (cu_str_t str)
cu_bool_t cuos_is_pathcomp_charr (char const *s, size_t len)
cu_bool_t cuos_is_pathcomp_cstr (char const *s)
int cuos_path_component_count (cu_str_t path)
int cuos_path_depth (cu_str_t path)
cu_bool_t cuos_path_is_empty (cu_str_t path)
cu_str_t cuos_path_cat2 (cu_str_t path0, cu_str_t path1)
cu_str_t cuos_path_cat2_sc (cu_str_t path0, char const *path1)
cu_str_t cuos_path_cat2_cs (char const *path0, cu_str_t path1)
cu_str_t cuos_path_cat2_cc (char const *path0, char const *path1)
cu_str_t cuos_path_cat3 (cu_str_t path0, cu_str_t path1, cu_str_t path2)
cu_str_t cuos_path_cat3_ssc (cu_str_t path0, cu_str_t path1, char const *path2)
cu_str_t cuos_path_cat3_scs (cu_str_t path0, char const *path1, cu_str_t path2)
cu_str_t cuos_path_cat3_css (char const *path0, cu_str_t path1, cu_str_t path2)
cu_str_t cuos_path_cat3_ccc (char const *path0, char const *path1, char const *path2)
cu_bool_t cuos_path_split (cu_str_t path, int pos, cu_str_t *path0, cu_str_t *path1)
cu_str_t cuos_path_dir (cu_str_t path)
cu_str_t cuos_path_base (cu_str_t path)
cu_str_t cuos_path_ext (cu_str_t path)
cu_str_t cuos_path_sans_ext (cu_str_t path)
cu_bool_t cuos_path_ext_eq (cu_str_t path, cu_str_t ext)
cu_bool_t cuos_path_ext_eq_charr (cu_str_t path, char const *s, size_t n)
cu_bool_t cuos_path_ext_eq_cstr (cu_str_t path, char const *ext)

Detailed Description

Definition (normalised file name). A normalised file name is a string subject to the following restrictions. The maximum substrings not containing "/" are called components. Components of the form "", "." and ".." are called special components. A file name is either absolute or relative. An normalised absolute file name is either "/", or starts with an empty component followed by one or more non-special components. A normalised relative file name is either ".", or it starts with zero or more "..", followed by zero or more non-special components, but adding up to at least one component.

 NFN		::= relative_NFN
 		  | absolute_NFN
 relative_NFN	::= "."
 		  | "../"* ".."
		  | "../"* (non_special_comp "/")* non_special_comp
 absolute_NFN	::= "/"
 		  | ("/" non_special_comp)+
 

Function Documentation

cu_bool_t cuos_is_path_charr ( char const *  s,
size_t  len 
)

True iff the string from s to s + len is a normalised file name.

cu_bool_t cuos_is_path_cstr ( char const *  s  ) 

True iff s is a normalised file name.

cu_bool_t cuos_is_path_str ( cu_str_t  str  ) 

True iff str is a normalised file name.

cu_bool_t cuos_is_pathcomp_charr ( char const *  s,
size_t  len 
)

True iff the string from s to s + len is valid as a non-special path component. See note under cuos_is_pathcomp_str.

cu_bool_t cuos_is_pathcomp_cstr ( char const *  s  ) 

True iff s is valid as a non-special path component. See note under cuos_is_pathcomp_str.

cu_bool_t cuos_is_pathcomp_str ( cu_str_t  str  ) 

True iff str is valid as a non-special path component.

Note:
It also returns false if the string contains ASCII non-printable characters. It does not check non-ASCII (UTF-8 encoded) non-printables, but this may change. Special path components are "." and "..". Beware that some file systems may have others as well, which are not checked for currently.
cu_str_t cuos_path_base ( cu_str_t  path  ) 

Same as ret, where

 cuos_path_split(path, -1, NULL, &ret)

.

cu_str_t cuos_path_cat2 ( cu_str_t  path0,
cu_str_t  path1 
)

Given that path0 and path1 are normalised file names, if path1 is absolute, return path1, else return the normalised file name of path1 relative to path0, i.e. the normalisation of the concatenation of (path0, "/", path1). path1 must be non-empty.

cu_str_t cuos_path_cat2_cc ( char const *  path0,
char const *  path1 
)

As cuos_path_cat2 but with 2 C string arguments.

cu_str_t cuos_path_cat2_cs ( char const *  path0,
cu_str_t  path1 
)

As cuos_path_cat2 but with C string as first argument.

cu_str_t cuos_path_cat2_sc ( cu_str_t  path0,
char const *  path1 
)

As cuos_path_cat2 but with C string as second argument.

int cuos_path_component_count ( cu_str_t  path  ) 

Return the number of components of path, where "." counts as zero and other components, including a leading "/" counts as one.

int cuos_path_depth ( cu_str_t  path  ) 

Returns the depth of path, where each non-special component and a leading "/" counts as one, "." counts as zero, and ".." counts as -1.

cu_str_t cuos_path_dir ( cu_str_t  path  ) 

Same as ret, where

 cuos_path_split(path, -1, &ret, NULL)

.

cu_str_t cuos_path_ext ( cu_str_t  path  ) 

Returns extension of path, including the ".", or an empty string if path has no extension.

cu_bool_t cuos_path_ext_eq ( cu_str_t  path,
cu_str_t  ext 
)

True iff path ends with ext.

cu_bool_t cuos_path_ext_eq_charr ( cu_str_t  path,
char const *  s,
size_t  n 
)

True iff path ends with the substring from s to s + n.

cu_bool_t cuos_path_ext_eq_cstr ( cu_str_t  path,
char const *  ext 
)

True iff path ends with ext.

cu_str_t cuos_path_from_charr ( char const *  s,
size_t  len 
)

Create normalised file names from the string from s to s + len or NULL if it is not a valid file name.

cu_str_t cuos_path_from_cstr ( char const *  s  ) 

Returns a normalised file name from s, or NULL if s does not hold a valid file name.

cu_str_t cuos_path_from_str ( cu_str_t  str  ) 

Returns a normalised file name from str, or NULL if str does not hold a valid file name.

cu_bool_t cuos_path_is_abs ( cu_str_t  path  ) 

True iff the normalised file name path is absolute.

cu_bool_t cuos_path_is_empty ( cu_str_t  path  ) 

True iff path has no components, i.e. it is ".". This is faster than using cuos_path_component_count.

cu_str_t cuos_path_sans_ext ( cu_str_t  path  ) 

Returns path without its extension or path itself if it has no extension.

cu_bool_t cuos_path_split ( cu_str_t  path,
int  pos,
cu_str_t path0,
cu_str_t path1 
)
Precondition:
path is a normalised file name.

If pos ≥ 0, then split path before component pos and store the first and last parts as a normalised file names in *path0 and *path1, respectively. If pos < 0, the call is equivalent to one where pos is replaced by n + pos, where n is the number of components.

Generated 2009-11-23 for culibs-0.25 using Doxygen. Maintained by Petter Urkedal.