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 336531 - Glib should have a function that changes a relative path to an absolute one.
Glib should have a function that changes a relative path to an absolute one.
Status: RESOLVED DUPLICATE of bug 8616
Product: glib
Classification: Platform
Component: general
2.10.x
Other All
: Normal enhancement
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2006-03-29 19:02 UTC by Javeed Shaikh
Modified: 2006-03-29 19:34 UTC
See Also:
GNOME target: ---
GNOME version: Unversioned Enhancement



Description Javeed Shaikh 2006-03-29 19:02:51 UTC
It would be nice if Glib had a funtion that changed a relative path to an
absolute one (to go along with all of the other nice path functions that it
has.) An implementation of this funtion using glibmm follows:

Glib::ustring path_to_abs_path(Glib::ustring path) {
        unsigned parents = 0;
        Glib::ustring cwd = Glib::get_current_dir();
        Glib::ustring::size_type pos;

        // find out how far up we have to go.
        while( (pos = path.find("../", 0)) !=Glib::ustring::npos ) {
                path.erase(0, 3);
                parents++;
        }
        
        // now erase that many directories from the path to the current
        // directory.
        
        while( parents ) {
                if ( (pos = cwd.rfind ('/')) != Glib::ustring::npos) {
                        // remove this directory from the path
                        cwd.erase (pos);
                }
                parents--;
        }
        
        return cwd + '/' + path;
}
Comment 1 Matthias Clasen 2006-03-29 19:34:15 UTC
This would be part of a general path handling api.

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