-#if defined __GLIBC__ && __GLIBC__ >= 2
- return getcwd (NULL, 0);
-#else
- char *ret;
- unsigned path_max;
- char buf[1024];
-
- errno = 0;
- ret = getcwd (buf, sizeof (buf));
- if (ret != NULL)
- return xstrdup (buf);
- if (errno != ERANGE)
- return NULL;
-
- path_max = 1300;
- path_max += 2; /* The getcwd docs say to do this. */
-
- for (;;)
- {
- char *cwd = (char *) xmalloc (path_max);
-
- errno = 0;
- ret = getcwd (cwd, path_max);
- if (ret != NULL)
- return ret;
- if (errno != ERANGE)
- {
- int save_errno = errno;
- free (cwd);
- errno = save_errno;
- return NULL;
- }
-
- free (cwd);
-
- path_max += path_max / 16;
- path_max += 32;
- }
-#endif
+ char *cwd = getcwd (NULL, 0);
+ if (! cwd && errno == ENOMEM)
+ xalloc_die ();
+ return cwd;