-#else
-
- int saved_errno;
-
- /* The initial buffer size for the working directory. A power of 2
- detects arithmetic overflow earlier, but is not required. */
-# ifndef INITIAL_BUFFER_SIZE
-# define INITIAL_BUFFER_SIZE 128
-# endif
-
- size_t buf_size = INITIAL_BUFFER_SIZE;
-
- while (1)
- {
- char *buf = xmalloc (buf_size);
- char *cwd = getcwd (buf, buf_size);
- if (cwd)
- return cwd;
- saved_errno = errno;
- free (buf);
- if (saved_errno != ERANGE)
- break;
-
-#ifdef PATH_MAX
- if (PATH_MAX / 2 < buf_size)
- {
- if (PATH_MAX <= buf_size)
- break;
- buf_size = PATH_MAX;
- continue;
- }
-#endif
-
- buf_size *= 2;
- if (buf_size == 0)
- xalloc_die ();
- }
-
- errno = saved_errno;
- return NULL;
-#endif