Next: , Previous: , Up: parser-tools unix-pathnames   [Index]


54.1.6 Manipulating Unix pathnames

The following bindings are exported by the library (vicare parser-tools unix-pathnames).

Function: normalise-segments absolute? segments

Given a list of bytevectors representing Unix pathname segments: normalise them, as much as possible, removing segments representing single–dot and double–dot directory entries; if absolute? is true: normalise segments as an absolute pathname, else normalise it as a relative pathname. Return two values:

  1. A boolean, #t if some change was made from segments to the second return value; this allows us to detect if a normalised list of segments when serialised into a bytevector becomes different from the original bytevector that generated segments.
  2. A new, possibly empty, list of bytevectors representing the normalisation of segments. Absolute pathname segments can hold neither single–dot nor double–dot segments: if a double–dot segment cannot annihilate its previous segment, it is just discarded.
Function: serialise-segments absolute? segments

Given a possibly empty list of bytevectors representing pathname segments build and return a new bytevector representing the full pathname; if absolute? is true: the first byte of the result represents a slash in ASCII coding.

If segments is null and absolute? is true: the returned value is a bytevector holding a single byte representing a slash in ASCII coding.

If segments is null and absolute? is false: the returned value is a bytevector holding a single byte representing a dot in ASCII coding.