Function

GLibcanonicalize_filename

since: 2.58

Declaration [src]

gchar*
g_canonicalize_filename (
  const gchar* filename,
  const gchar* relative_to
)

Description [src]

Gets the canonical file name from filename. All triple slashes are turned into single slashes, and all .. and .s resolved against relative_to.

Symlinks are not followed, and the returned path is guaranteed to be absolute.

If filename is an absolute path, relative_to is ignored. Otherwise, relative_to will be prepended to filename to make it absolute. relative_to must be an absolute path, or NULL. If relative_to is NULL, it’ll fallback to g_get_current_dir().

This function never fails, and will canonicalize file paths even if they don’t exist.

No file system I/O is done.

Available since: 2.58

Parameters

filename

Type: const gchar*

The name of the file.

The data is owned by the caller of the function.
The value is a platform-native string, using the preferred OS encoding on Unix and UTF-8 on Windows.
relative_to

Type: const gchar*

The relative directory, or NULL to use the current working directory.

The argument can be NULL.
The data is owned by the caller of the function.
The value is a platform-native string, using the preferred OS encoding on Unix and UTF-8 on Windows.

Return value

Type: gchar*

A newly allocated string with the canonical file path.

The caller of the function takes ownership of the data, and is responsible for freeing it.
The value is a platform-native string, using the preferred OS encoding on Unix and UTF-8 on Windows.