-#if defined __GLIBC__ && __GLIBC__ >= 2
- return getcwd (NULL, 0);
-#else
- char *ret;
- size_t 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 = 1 << 10;
-
- for (;;)
- {
- char *cwd = (char *) xmalloc (path_max);
- int save_errno;
-
- errno = 0;
- ret = getcwd (cwd, path_max);
- if (ret != NULL)
- return ret;
- save_errno = errno;
- free (cwd);
- if (save_errno != ERANGE)
- {
- errno = save_errno;
- return NULL;
- }
-
- path_max *= 2;
- if (path_max == 0)
- xalloc_die ();
- }
-#endif
+ char *cwd = getcwd (NULL, 0);
+ if (! cwd && errno == ENOMEM)
+ xalloc_die ();
+ return cwd;