summaryrefslogtreecommitdiff
path: root/lib/link.c
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2011-06-22 12:15:02 -0600
committerEric Blake <eblake@redhat.com>2011-06-22 12:36:54 -0600
commitdf1c2344f29dbca57d9e560aaa89aa2c20cdda7f (patch)
tree5a25ae197206b35a74628ea65fbf001845714459 /lib/link.c
parentcbf381169705782b144b2733798a62c11aa473a5 (diff)
downloadgnulib-df1c2344f29dbca57d9e560aaa89aa2c20cdda7f.tar.gz
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>
Diffstat (limited to 'lib/link.c')
-rw-r--r--lib/link.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/link.c b/lib/link.c
index 1b0fe0a0e9..b58eb25bc3 100644
--- a/lib/link.c
+++ b/lib/link.c
@@ -155,9 +155,20 @@ link (const char *file1, const char *file2)
int
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. */
- size_t len1 = strlen (file1);
- size_t len2 = strlen (file2);
+ len1 = strlen (file1);
+ len2 = strlen (file2);
if ((len1 && file1[len1 - 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
(although on Solaris 9, link("file/","oops") mistakenly
succeeds); if stat() succeeds, require a directory. */
- struct stat st;
if (stat (file1, &st))
return -1;
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". */
char *dir = strdup (file2);
- struct stat st;
char *p;
if (!dir)
return -1;