11. Path

The path(3m) module provides functions for some common path manipulations.

11.1. Path functions

The path_canon function
Synopsis

#include <mba/path.h> int path_canon(const unsigned char *src, const unsigned char *slim, unsigned char *dst, unsigned char *dlim, int srcsep, int dstsep);
Description
The path_canon function canonicalizes the path at src up to but not including the memory at slim into the memory at dst up to but not including dlim. The character that separates path components in the src path is specified with the srcsep parameter whereas dstsep specifies the separator with which the dst path is constructed.

Specifically, canonicalization will eliminate '.' and '..' components in paths in the conventional way as well as normalize redundant separators. The presence or lack of an initial and/or trailing separator is preserved. The following lists some examples of paths before and after canonicalization:

  before      after
  .
  ..
  /           /
  /.          /
  ./
  ../
  .../        .../
  a/..        
  abc/../
  a/b/c       a/b/c
  /a/b/c      /a/b/c 
  /./a/b/c    /a/b/c
  /../a/b/c   /a/b/c
  ..a/b/c     ..a/b/c
  a/b/c/      a/b/c/
  a/b/c/..    a/b/
  a/b/c/../   a/b/
  a/b/c/./    a/b/c/
  
Returns
The path_canon function returns the number of bytes written to dst not including the zero terminator or -1 if slim or dlim has been reached in which case errno is set to ERANGE.


Copyright 2003 Michael B. Allen <mba2000 ioplex.com>