mirror of
https://git.savannah.gnu.org/git/gnulib.git
synced 2025-08-17 12:41:05 +03:00
getcwd-lgpl: relax test for FreeBSD
getcwd(NULL, 1) mallocs a larger buffer on BSD, rather than failing with ERANGE as on glibc. This behavior difference is not worth coding around, as it is an uncommon use of getcwd in the first place. * doc/posix-functions/getcwd.texi (getcwd): Document portability issue. * tests/test-getcwd-lgpl.c (main): Relax test. Reported by Matthias Bolte. Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
@@ -1,3 +1,11 @@
|
|||||||
|
2011-05-13 Eric Blake <eblake@redhat.com>
|
||||||
|
|
||||||
|
getcwd-lgpl: relax test for FreeBSD
|
||||||
|
* doc/posix-functions/getcwd.texi (getcwd): Document portability
|
||||||
|
issue.
|
||||||
|
* tests/test-getcwd-lgpl.c (main): Relax test.
|
||||||
|
Reported by Matthias Bolte.
|
||||||
|
|
||||||
2011-05-11 Eric Blake <eblake@redhat.com>
|
2011-05-11 Eric Blake <eblake@redhat.com>
|
||||||
|
|
||||||
test-fflush: silence compiler warning
|
test-fflush: silence compiler warning
|
||||||
|
@@ -11,8 +11,7 @@ Portability problems fixed by either Gnulib module @code{getcwd} or
|
|||||||
@itemize
|
@itemize
|
||||||
@item
|
@item
|
||||||
On glibc platforms, @code{getcwd (NULL, n)} allocates memory for the result.
|
On glibc platforms, @code{getcwd (NULL, n)} allocates memory for the result.
|
||||||
On some other platforms, this call is not allowed. Conversely, mingw fails
|
On some other platforms, this call is not allowed.
|
||||||
to honor non-zero @code{n}.
|
|
||||||
@item
|
@item
|
||||||
On some platforms, the prototype for @code{getcwd} uses @code{int}
|
On some platforms, the prototype for @code{getcwd} uses @code{int}
|
||||||
instead of @code{size_t} for the size argument:
|
instead of @code{size_t} for the size argument:
|
||||||
@@ -30,4 +29,11 @@ correctly on some platforms.
|
|||||||
|
|
||||||
Portability problems not fixed by Gnulib:
|
Portability problems not fixed by Gnulib:
|
||||||
@itemize
|
@itemize
|
||||||
|
@item
|
||||||
|
When using @code{getcwd(NULL, nonzero)}, some platforms, such as glibc
|
||||||
|
or cygwin, allocate exactly @code{nonzero} bytes and fail with
|
||||||
|
@code{ERANGE} if it was not big enough, while other platforms, such as
|
||||||
|
FreeBSD or mingw, ignore the size argument and allocate whatever size
|
||||||
|
is necessary. If this call succeeds, an application cannot portably
|
||||||
|
access beyond the string length of the result.
|
||||||
@end itemize
|
@end itemize
|
||||||
|
@@ -65,12 +65,22 @@ main (int argc, char **argv)
|
|||||||
pwd2 = malloc (len + 2);
|
pwd2 = malloc (len + 2);
|
||||||
for ( ; i <= len; i++)
|
for ( ; i <= len; i++)
|
||||||
{
|
{
|
||||||
|
char *tmp;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
ASSERT (getcwd (pwd2, i) == NULL);
|
ASSERT (getcwd (pwd2, i) == NULL);
|
||||||
ASSERT (errno == ERANGE);
|
ASSERT (errno == ERANGE);
|
||||||
|
/* Allow either glibc or BSD behavior, since POSIX allows both. */
|
||||||
errno = 0;
|
errno = 0;
|
||||||
ASSERT (getcwd (NULL, i) == NULL);
|
tmp = getcwd (NULL, i);
|
||||||
ASSERT (errno == ERANGE);
|
if (tmp)
|
||||||
|
{
|
||||||
|
ASSERT (strcmp (pwd1, tmp) == 0);
|
||||||
|
free (tmp);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ASSERT (errno == ERANGE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ASSERT (getcwd (pwd2, len + 1) == pwd2);
|
ASSERT (getcwd (pwd2, len + 1) == pwd2);
|
||||||
pwd2[len] = '/';
|
pwd2[len] = '/';
|
||||||
@@ -80,6 +90,11 @@ main (int argc, char **argv)
|
|||||||
ASSERT (strstr (pwd2, "/../") == NULL);
|
ASSERT (strstr (pwd2, "/../") == NULL);
|
||||||
ASSERT (strstr (pwd2 + 1 + (pwd2[1] == '/'), "//") == NULL);
|
ASSERT (strstr (pwd2 + 1 + (pwd2[1] == '/'), "//") == NULL);
|
||||||
|
|
||||||
|
/* Validate a POSIX requirement on size. */
|
||||||
|
errno = 0;
|
||||||
|
ASSERT (getcwd(pwd2, 0) == NULL);
|
||||||
|
ASSERT (errno == EINVAL);
|
||||||
|
|
||||||
free (pwd1);
|
free (pwd1);
|
||||||
free (pwd2);
|
free (pwd2);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user