1 /* vi: set sw=4 ts=4: */
3 * xgetcwd.c -- return current directory with unlimited length
4 * Copyright (C) 1992, 1996 Free Software Foundation, Inc.
5 * Written by David MacKenzie <djm@gnu.ai.mit.edu>.
7 * Special function for busybox written by Vladimir Oleynik <dzo@simtreas.ru>
14 #include <sys/param.h>
17 /* Amount to increase buffer size by in each try. */
20 /* Return the current directory, newly allocated, arbitrarily long.
21 Return NULL and set errno on error.
22 If argument is not NULL (previous usage allocate memory), call free()
31 path_max = (unsigned) PATH_MAX;
32 path_max += 2; /* The getcwd docs say to do this. */
35 cwd = xmalloc (path_max);
37 while ((ret = getcwd (cwd, path_max)) == NULL && errno == ERANGE) {
38 path_max += PATH_INCR;
39 cwd = xrealloc (cwd, path_max);
44 bb_perror_msg("getcwd()");