[Haskell-cafe] Re: File path programme

robert dockins robdockins at fastmail.fm
Mon Jan 31 15:08:30 EST 2005

> Well, there is a sort-of canonic version for every path; on
> most Unix systems the function realpath(3) will find it.

Here is the BUGS listing from 'man realpath' on my system:

Never use this function. It is broken by design since it is impossible 
to determine a suitable size for the output  buffer. According  to 
POSIX  a  buffer  of size PATH_MAX suffices, but PATH_MAX need not be a 
defined constant, and may have to be obtained using pathconf().  And 
asking pathconf() does not really help, since on the one hand POSIX 
warns that  the  result of  pathconf()  may  be huge and unsuitable for 
mallocing memory. And on the other hand pathconf() may return -1 to 
signify that PATH_MAX is not bounded.

 > My interpretation is that two paths are equivalent iff they
 > point to the same target.

You might do better (on *nix) to check if two paths terminate in the 
same filesystem and then see if the inode numbers match (with some stat 
variant).  Even that may break down for networked filesystems or FAT 
wrappers or other things that may lie about the inode number.

You could also unravel the path manually, but that seems error-prone and 

This strikes me as yet another case of a simple-seeming operation that 
simply cannot be implemented correctly on file names.

More information about the Haskell-Cafe mailing list