-#if defined __GLIBC__ && __GLIBC__ >= 2
- return getcwd (NULL, 0);
-#else
- size_t buf_size = 128; /* must be a power of 2 */
- char *buf = NULL;
-
- while (1)
- {
- char *cwd;
- buf = (char *) xrealloc (buf, buf_size);
-
- cwd = getcwd (buf, buf_size);
- if (cwd != NULL)
- return cwd;
- if (errno != ERANGE)
- {
- free (buf);
- return NULL;
- }
-
- buf_size *= 2;
- if (buf_size == 0)
- xalloc_die ();
- }
-#endif
+ char *cwd = getcwd (NULL, 0);
+ if (! cwd && errno == ENOMEM)
+ xalloc_die ();
+ return cwd;