SHTK_FS_NORMALIZE_PATH(3)
SHTK_FS_NORMALIZE_PATH(3) Library Functions Manual SHTK_FS_NORMALIZE_PATH(3)

shtk_fs_normalize_pathReturns a normalized form of a path

shtk_import fs

shtk_fs_normalize_path path

The shtk_fs_normalize_path function takes the given path and prints its normalized form to stdout.

This process involves the following:

  • Collapsing multiple consecutive forward slashes into one.
  • Adding a . component at the beginning of the path if it is relative.
  • Removing any . components, except for the first one.
  • Removing any trailing slashes.

Note that the normalization happens performing any file system operations. Therefore, it is perfectly possible for two normalized paths that look different to point to the same file system entry. In particular, this is because normalization does not take into account links nor .. components.

shtk_fs_normalize_path returns 0.

shtk_fs_normalize_path /foo/bar  # Prints /foo/bar
shtk_fs_normalize_path foo/bar  # Prints ./foo/bar
shtk_fs_normalize_path foo///bar/./baz//  # Prints ./foo/bar/baz

shtk(3), shtk_fs(3)

shtk_fs_normalize_path first appeared in shtk 1.7.

September 18, 2016 Debian