mirror of
https://git.savannah.gnu.org/git/gnulib.git
synced 2025-08-17 12:41:05 +03:00
link: work around IRIX bug
On IRIX 6.5, link(file, "dangling") creates the target of dangling as a link to file, rather than failing with EEXIST. * m4/link.m4 (gl_FUNC_LINK): Expose the bug. * lib/link.c (rpl_link): Work around it. * tests/test-link.h (test_link): Enhance test. * doc/posix-functions/link.texi (link): Document the bug. Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
@@ -1,5 +1,11 @@
|
|||||||
2011-06-22 Eric Blake <eblake@redhat.com>
|
2011-06-22 Eric Blake <eblake@redhat.com>
|
||||||
|
|
||||||
|
link: work around IRIX bug
|
||||||
|
* m4/link.m4 (gl_FUNC_LINK): Expose the bug.
|
||||||
|
* lib/link.c (rpl_link): Work around it.
|
||||||
|
* tests/test-link.h (test_link): Enhance test.
|
||||||
|
* doc/posix-functions/link.texi (link): Document the bug.
|
||||||
|
|
||||||
getopt: silence clang warning
|
getopt: silence clang warning
|
||||||
* lib/getopt.c (_getopt_internal_r): Avoid unlikely NULL
|
* lib/getopt.c (_getopt_internal_r): Avoid unlikely NULL
|
||||||
dereference.
|
dereference.
|
||||||
|
@@ -15,6 +15,10 @@ mingw.
|
|||||||
This function fails to reject trailing slashes on non-directories on
|
This function fails to reject trailing slashes on non-directories on
|
||||||
some platforms:
|
some platforms:
|
||||||
FreeBSD 7.2, Solaris 11 2010-11, Cygwin 1.5.x.
|
FreeBSD 7.2, Solaris 11 2010-11, Cygwin 1.5.x.
|
||||||
|
@item
|
||||||
|
When the second argument is a dangling symlink, some platforms follow
|
||||||
|
that link and create the destination rather than failing:
|
||||||
|
IRIX 6.5.
|
||||||
@end itemize
|
@end itemize
|
||||||
|
|
||||||
Portability problems not fixed by Gnulib:
|
Portability problems not fixed by Gnulib:
|
||||||
|
17
lib/link.c
17
lib/link.c
@@ -155,9 +155,20 @@ link (const char *file1, const char *file2)
|
|||||||
int
|
int
|
||||||
rpl_link (char const *file1, char const *file2)
|
rpl_link (char const *file1, char const *file2)
|
||||||
{
|
{
|
||||||
|
size_t len1;
|
||||||
|
size_t len2;
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
|
/* Don't allow IRIX to dereference dangling file2 symlink. */
|
||||||
|
if (!lstat (file2, &st))
|
||||||
|
{
|
||||||
|
errno = EEXIST;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Reject trailing slashes on non-directories. */
|
/* Reject trailing slashes on non-directories. */
|
||||||
size_t len1 = strlen (file1);
|
len1 = strlen (file1);
|
||||||
size_t len2 = strlen (file2);
|
len2 = strlen (file2);
|
||||||
if ((len1 && file1[len1 - 1] == '/')
|
if ((len1 && file1[len1 - 1] == '/')
|
||||||
|| (len2 && file2[len2 - 1] == '/'))
|
|| (len2 && file2[len2 - 1] == '/'))
|
||||||
{
|
{
|
||||||
@@ -165,7 +176,6 @@ rpl_link (char const *file1, char const *file2)
|
|||||||
If stat() fails, then link() should fail for the same reason
|
If stat() fails, then link() should fail for the same reason
|
||||||
(although on Solaris 9, link("file/","oops") mistakenly
|
(although on Solaris 9, link("file/","oops") mistakenly
|
||||||
succeeds); if stat() succeeds, require a directory. */
|
succeeds); if stat() succeeds, require a directory. */
|
||||||
struct stat st;
|
|
||||||
if (stat (file1, &st))
|
if (stat (file1, &st))
|
||||||
return -1;
|
return -1;
|
||||||
if (!S_ISDIR (st.st_mode))
|
if (!S_ISDIR (st.st_mode))
|
||||||
@@ -178,7 +188,6 @@ rpl_link (char const *file1, char const *file2)
|
|||||||
{
|
{
|
||||||
/* Fix Cygwin 1.5.x bug where link("a","b/.") creates file "b". */
|
/* Fix Cygwin 1.5.x bug where link("a","b/.") creates file "b". */
|
||||||
char *dir = strdup (file2);
|
char *dir = strdup (file2);
|
||||||
struct stat st;
|
|
||||||
char *p;
|
char *p;
|
||||||
if (!dir)
|
if (!dir)
|
||||||
return -1;
|
return -1;
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
# link.m4 serial 6
|
# link.m4 serial 7
|
||||||
dnl Copyright (C) 2009-2011 Free Software Foundation, Inc.
|
dnl Copyright (C) 2009-2011 Free Software Foundation, Inc.
|
||||||
dnl This file is free software; the Free Software Foundation
|
dnl This file is free software; the Free Software Foundation
|
||||||
dnl gives unlimited permission to copy and/or distribute it,
|
dnl gives unlimited permission to copy and/or distribute it,
|
||||||
@@ -11,7 +11,7 @@ AC_DEFUN([gl_FUNC_LINK],
|
|||||||
if test $ac_cv_func_link = no; then
|
if test $ac_cv_func_link = no; then
|
||||||
HAVE_LINK=0
|
HAVE_LINK=0
|
||||||
else
|
else
|
||||||
AC_CACHE_CHECK([whether link handles trailing slash correctly],
|
AC_CACHE_CHECK([whether link obeys POSIX],
|
||||||
[gl_cv_func_link_works],
|
[gl_cv_func_link_works],
|
||||||
[touch conftest.a
|
[touch conftest.a
|
||||||
# Assume that if we have lstat, we can also check symlinks.
|
# Assume that if we have lstat, we can also check symlinks.
|
||||||
@@ -28,6 +28,10 @@ AC_DEFUN([gl_FUNC_LINK],
|
|||||||
#if HAVE_LSTAT
|
#if HAVE_LSTAT
|
||||||
if (!link ("conftest.lnk/", "conftest.b"))
|
if (!link ("conftest.lnk/", "conftest.b"))
|
||||||
result |= 2;
|
result |= 2;
|
||||||
|
if (rename ("conftest.a", "conftest.b"))
|
||||||
|
result |= 4;
|
||||||
|
if (!link ("conftest.b", "conftest.lnk"))
|
||||||
|
result |= 8;
|
||||||
#endif
|
#endif
|
||||||
return result;
|
return result;
|
||||||
]])],
|
]])],
|
||||||
|
@@ -166,6 +166,9 @@ test_link (int (*func) (char const *, char const *), bool print)
|
|||||||
ASSERT (func (BASE "b", BASE "link/") == -1);
|
ASSERT (func (BASE "b", BASE "link/") == -1);
|
||||||
ASSERT (errno == ENOTDIR || errno == ENOENT || errno == EEXIST
|
ASSERT (errno == ENOTDIR || errno == ENOENT || errno == EEXIST
|
||||||
|| errno == EINVAL);
|
|| errno == EINVAL);
|
||||||
|
errno = 0;
|
||||||
|
ASSERT (func (BASE "b", BASE "link") == -1);
|
||||||
|
ASSERT (errno == EEXIST);
|
||||||
ASSERT (rename (BASE "b", BASE "a") == 0);
|
ASSERT (rename (BASE "b", BASE "a") == 0);
|
||||||
errno = 0;
|
errno = 0;
|
||||||
ASSERT (func (BASE "link/", BASE "b") == -1);
|
ASSERT (func (BASE "link/", BASE "b") == -1);
|
||||||
|
Reference in New Issue
Block a user