Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: pathconf() again

On Aug 4,  9:19am, Clint Adams wrote:
> Subject: Re: PATCH: pathconf() again
> > Random questions:  Can someone explain how one is supposed to determine a
> > useful buffer size for e.g. readlink() if pathconf() returns `unlimited'?
> What I was told is that one should malloc an arbitrary amount, say 512
> bytes, then realloc to double the buffer size if it's too small.  Rinse
> and repeat.

But ... readlink() doesn't have any provision to "read more of the link"
and doesn't tell you if it truncated what it did read.

In that specific instance, I suppose you could allocate space based on
the st_size returned by lstat(), but the general solution feels sloppy
at best.

> > For that matter, how does one even know what directory name to pass into
> > pathconf() in that case?
> I assume you want the PATH_MAX of the filesystem where the link lives,
> and not the psychically-determined filesystem to which it's pointing.

Only if it's a relative rather than absolute link.

Messages sorted by: Reverse Date, Date, Thread, Author