Bruno Haible wrote: > In a testdir for module getcwd, I get this test failure on AIX 5.1, 5.2, 5.3, > 6.1, 7.1: > > FAIL: test-getcwd.sh > > On this platform, configure says: > > checking whether getcwd (NULL, 0) allocates memory for result... no > checking for getcwd with POSIX signature... yes > checking whether getcwd is declared... yes > checking whether getcwd is declared without a macro... yes > > The test program test-getcwd fails with exit code 4. > > What's happening? After creating a sufficiently large number of > subdirectories, > the statement > > c = getcwd (buf, PATH_MAX); > > produces c = buf, strlen (c) = 1021 (whereas PATH_MAX = 1023), and > the result in buf is > > /haible/multibuild-1511/aix51-cc/testdir1/gltests/confdir3/{...}/confdir3 > > which is wrong: The result should be > > /home/haible/multibuild-1511/aix51-cc/testdir1/gltests/confdir3/{...}/confdir3 > > That is, the system's getcwd function and with it also the rpl_getcwd > function has returned a file name with a missing *first* component, > and errno is still 0, giving no indication to the failure. > > > Either of the two following patches fixes it. Which one do you prefer?
Is there an advantage to using the system getcwd for names shorter than PATH_MAX, as there is on Solaris and systems with a linux kernel? (i.e., ability to function in spite of restricted permissions on a parent directory) If so, I think we must prefer the latter, even though it incurs the additional overhead (albeit only on AIX) of two lstat calls per component. > 2011-11-20 Bruno Haible <br...@clisp.org> > > getcwd: Work around getcwd bug on AIX 5..7. > * lib/getcwd.c (__getcwd): Don't use the system's getcwd on AIX. > * doc/posix-functions/getcwd.texi: Mention list of platforms where > getcwd does not handle long file names. > ... > 2011-11-20 Bruno Haible <br...@clisp.org> > > getcwd: Work around getcwd bug on AIX 5..7. > * lib/getcwd.c (__getcwd): On AIX, verify the system's getcwd result > before returning it. > * doc/posix-functions/getcwd.texi: Mention list of platforms where > getcwd does not handle long file names. > ... > ! # ifdef _AIX > ! /* On AIX 5.1..7.1, the system getcwd can succeed and produce a > ! wrong result: If the current directory name is slightly longer > ! than PATH_MAX, it omits the first directory component and > ! returns this wrong result with errno = 0. */ > ! struct stat st2; > ! > ! if (__lstat (".", &st) >= 0 > ! && __lstat (dir, &st2) >= 0 > ! && st.st_dev == st2.st_dev && st.st_ino == st2.st_ino) > ! return dir; > ! # else > ! return dir; > ! # endif ... Thanks for writing the test program (I haven't really looked at it, though).