2 * xgetcwd.c -- return current directory with unlimited length
3 * Copyright (C) 1992, 1996 Free Software Foundation, Inc.
4 * Written by David MacKenzie <djm@gnu.ai.mit.edu>.
6 * Special function for busybox written by Vladimir Oleynik <vodz@usa.net>
13 #include <sys/param.h>
16 /* Amount to increase buffer size by in each try. */
19 /* Return the current directory, newly allocated, arbitrarily long.
20 Return NULL and set errno on error.
21 If argument is not NULL (previous usage allocate memory), call free()
30 path_max = (unsigned) PATH_MAX;
31 path_max += 2; /* The getcwd docs say to do this. */
34 cwd = xmalloc (path_max);
36 while ((ret = getcwd (cwd, path_max)) == NULL && errno == ERANGE) {
37 path_max += PATH_INCR;
38 cwd = xrealloc (cwd, path_max);
43 perror_msg("getcwd()");