> I'm looking for a C algorithm to convert relative paths to an absolute
> path.
> For instance, I want to resolve "/usr/bin/X11/../ls" into "/usr/bin/ls."
> But I would also like to generally clean up a path as well; eg.
> "/usr/bin//ls" to "/usr/bin/ls," and so on.
> Years ago I saw an algorithm to do this, posted here, but I have since
> lost the darn thing.
Howdy Ross,
I was investigating the subject the other day and I found a function
that can do that, I think it is a GNU-specific function so you can
find a source for it on any FTP site carrying GNU software.
---------------------------------------------------------------------------
NAME
realpath - returns the canonicalized absolute pathname.
SYNOPSIS
#include <sys/param.h>
#include <unistd.h>
char *realpath(char *path, char resolved_path[]);
DESCRIPTION
realpath expands all symbolic links and resolves references to '/./', '/../'
and extra '/' characters in the null terminated string named by path and
stores the canonicalized absolute pathname in the buffer of size MAXPATHLEN
named by resolved_path. The resulting path will have no symbolic link, '/./'
or '/../' components.
[ THE REST SNIPPED ]
-----------------------------------------------------------------------------
--
#include <disclaimer.h> | *Good pings come in small packets*
Vancouver | Windows: for IQs smaller than 95
British Columbia | SIGSIG -- signature too long (core dumped)