"James Youngman" <j...@gnu.org> wrote: > On Mon, Dec 15, 2008 at 12:18 AM, Bruno Haible <br...@clisp.org> wrote: >> However, for openat-die.c I don't see a good replacement. In particular, I >> don't see a way how openat_restore_fail() could be handled in library code. >> A program cannot simply continue when its current directory is different from >> what it was expecting. And errno values don't adequately capture this >> situation. ?? Any ideas? > > I would suggest simply avoiding the case where save_cwd() calls > xgetcwd(). Certainly this will make openat() fail for directories > (other than the original current directory) which are not readable. > However, apart from that restriction, using only fchdir does have the > advantage that we know that restoring the current directory can't > fail. (It can fail IIRC on SunOS, but I think we don't support the > affected versions any more).
This would also cause failure when emulating openat support and running from an absolute directory whose name is longer than PATH_MAX. The real solution is to add support for POSIX.2008's proposed O_SEARCH open flag to our favorite kernels.