1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* Copyright (C) 2011 Free Software Foundation, Inc.
4 This file is part of gnulib.
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
28 /* Favor GPL getcwd.c if both getcwd and getcwd-lgpl modules are in use. */
32 /* Get the name of the current working directory, and put it in SIZE
33 bytes of BUF. Returns NULL if the directory couldn't be determined
34 (perhaps because the absolute name was longer than PATH_MAX, or
35 because of missing read/search permissions on parent directories)
36 or SIZE was too small. If successful, returns BUF. If BUF is
37 NULL, an array is allocated with `malloc'; the array is SIZE bytes
38 long, unless SIZE == 0, in which case it is as big as
43 rpl_getcwd (char *buf, size_t size)
48 /* Handle single size operations. */
56 return getcwd (buf, size);
67 result = getcwd (buf, size);
70 int saved_errno = errno;
77 /* Flexible sizing requested. Avoid over-allocation for the common
78 case of a name that fits within a 4k page, minus some space for
79 local variables, to be sure we don't skip over a guard page. */
83 ptr = getcwd (tmp, size);
86 result = strdup (ptr);
95 /* My what a large directory name we have. */
99 ptr = realloc (buf, size);
107 result = getcwd (buf, size);
109 while (!result && errno == ERANGE);
113 int saved_errno = errno;
119 /* Trim to fit, if possible. */
120 result = realloc (buf, strlen (buf) + 1);