After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 322822 - GLib enhancement: g_path_canonicalize()
GLib enhancement: g_path_canonicalize()
Status: RESOLVED DUPLICATE of bug 111848
Product: glib
Classification: Platform
Component: general
2.9.x
Other All
: Normal enhancement
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2005-11-30 10:44 UTC by Tor Lillqvist
Modified: 2006-01-21 17:29 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Tor Lillqvist 2005-11-30 10:44:24 UTC
A realpath() lookalike/enhancement would be nice. I am prepared to do it once we
agree on the API.

Suggested API:

typedef enum 
{ 
  G_PATH_CANONICALIZE_EXPAND_SYMLINKS   = 1 << 0,
  G_PATH_CANONICALIZE_WIN32_USE_SLASHES = 1 << 1
} GPathCanonicalizeFlags;

gchar *g_path_canonicalize (const gchar           *path, 
			    GPathCanonicalizeFlags flags, 
			    GError                *error);

Or is that overdoing it, should it just set errno on error?

Suggested API doc:

Return a more canonical absolute form of file name @path. If @path is
not absolute, the current directory is prefixed to it. A canonical
name does not contain any "." or ".." components nor any repeated path
separators.

If the G_PATH_CANONICALIZE_EXPAND_SYMLINKS flag is included in @flags,
symlinks are expanded on Unix. On Windows, junction points are
expanded. (??? this might be too hard to be feasible) In that case all
path components must exist.

If G_PATH_CANONICALIZE_EXPAND_SYMLINKS is not included, no file system
lookups are done, so the path need not refer to existing directories
and files at all.

The path separators in the returned name will all be the most
canonical ones, in case the platform has several. That is, on Windows
it will use backslashes. If the G_PATH_CANONICALIZE_WIN32_USE_SLASHES
flag is set in @flags, slashes will be used instead.

On Windows the returned name will have the \\?\ prefix if it otherwise
would be an illegal path, mainly if its length would be over 260 wide
chars (??? I mean the UTF-16 wchar_t, what's the correct name for a
UTF-16 element?). See the "Naming a File" documentation in MSDN.

Note that there is no guarantee that the result will be a unique name
for the file in cases where the same file is accessible through
several canonical paths. The obvious cases where this can happen are
linked files (on Unix), mounting the same (network) file system in
several locations, etc. This function should not be used for security
critical purposes.
Comment 1 Tristan Van Berkom 2006-01-21 17:29:34 UTC
Heh,
   looks like your on this ball and I wish I had used your code ;-)

bumped into bug 111848


*** This bug has been marked as a duplicate of 111848 ***