On Mon, Jul 25, 2005 at 12:19:00PM -0700, Bruce Korb wrote:
> Hmm. Interesting problem. The "realpath(3C)" documentation
> specifically references PATH_MAX:
>
> > NAME
> > realpath - return the canonicalized absolute pathname
> >
> > SYNOPSIS
> > #include <limits.h>
> > #include <stdlib.h>
> > char *realpath(const char *path, char *resolved_path);
> > [...]
> > ERRORS
> > [...]
> > ENAMETOOLONG
> > A component of a path name exceeded NAME_MAX
> > characters, or an entire path name exceeded PATH_MAX
> > characters.
>
> and the code in question is only compiled in if "realpath" is known
> to be in the library. And, yes, I know about the extended GNU doc:
>
> > BUGS
> > 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 mem- ory. And on the other hand
> > pathconf() may return -1 to signify that
> > PATH_MAX is not bounded.
>
> but since no viable alternative is suggested, it leaves one in a difficult
> spot.
The GNU C library manual (as in, libc.info.gz) suggests using
canonicalize_file_name in chapter 14.5, "Symbolic Links":
Function: char * canonicalize_file_name (const char *NAME)
The `canonicalize_file_name' function returns the absolute name of
the file named by NAME which contains no `.', `..' components nor
any repeated path separators (`/') or symlinks. The result is
passed back as the return value of the function in a block of
memory allocated with `malloc'. If the result is not used anymore
the memory should be freed with a call to `free'.
In any of the path components except the last one is missing the
function returns a NULL pointer. This is also what is returned if
the length of the path reaches or exceeds `PATH_MAX' characters.
In any case `errno' is set accordingly.
`ENAMETOOLONG'
The resulting path is too long. This error only occurs on
systems which have a limit on the file name length.
`EACCES'
At least one of the path components is not readable.
`ENOENT'
The input file name is empty.
`ENOENT'
At least one of the path components does not exist.
`ELOOP'
More than `MAXSYMLINKS' many symlinks have been followed.
This function is a GNU extension and is declared in `stdlib.h'.
So you could perhaps use this function if available (i.e. on GNU/Linux
and GNU/Hurd), and realpath() otherwise. I don't much about this
though, so maybe this is bad advise.
cheers,
Michael
--
Michael Banck
Debian Developer
[EMAIL PROTECTED]
http://www.advogato.org/person/mbanck/diary.html
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]