1 /* xgetcwd.c -- return current directory with unlimited length
2 Copyright (C) 1992, 1996, 2000, 2003, 2005-2006, 2011, 2015 Free
3 Software Foundation, Inc.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 /* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */
25 #include <sys/types.h>
30 /* In this file, PATH_MAX is the size of an initial memory allocation. */
32 # define PATH_MAX 8192
37 /* We want the directory in Unix syntax, not in VMS syntax. */
38 # define getcwd(Buf, Max) (getcwd) (Buf, Max, 0)
44 # define getcwd(Buf, Max) getwd (Buf)
49 /* Return the current directory, newly allocated, arbitrarily long.
50 Return NULL and set errno on error. */
60 ret = getcwd (buf, sizeof (buf));
66 path_max = (unsigned) PATH_MAX;
67 path_max += 2; /* The getcwd docs say to do this. */
71 char *cwd = XNMALLOC (path_max, char);
74 ret = getcwd (cwd, path_max);
79 int save_errno = errno;
87 path_max += path_max / 16;