X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-linkat.c;h=2bf17905243af3f4cd2e543f6bb8b064d444fc45;hb=6531b40e89ecb9a18480e87633f61b16286abe7e;hp=cee1c9972c485c07c1c6aa0ad49c0143a3ed92c0;hpb=85b6cb48e0f3bbf83420d9d4cd2d49049da64a87;p=gnulib.git diff --git a/tests/test-linkat.c b/tests/test-linkat.c index cee1c9972..2bf179052 100644 --- a/tests/test-linkat.c +++ b/tests/test-linkat.c @@ -1,5 +1,5 @@ /* Tests of linkat. - Copyright (C) 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 2009-2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -34,7 +34,6 @@ SIGNATURE_CHECK (linkat, int, (int, char const *, int, char const *, int)); #include "areadlink.h" #include "filenamecat.h" #include "same-inode.h" -#include "xgetcwd.h" #include "ignore-value.h" #include "macros.h" @@ -53,6 +52,17 @@ do_link (char const *name1, char const *name2) return linkat (dfd1, name1, dfd2, name2, flag); } +/* Can we expect that link() and linkat(), when called on a symlink, + increment the link count of that symlink? */ +#if LINK_FOLLOWS_SYMLINKS == 0 +# define EXPECT_LINK_HARDLINKS_SYMLINKS 1 +#elif LINK_FOLLOWS_SYMLINKS == -1 +extern int __xpg4; +# define EXPECT_LINK_HARDLINKS_SYMLINKS (__xpg4 == 0) +#else +# define EXPECT_LINK_HARDLINKS_SYMLINKS 0 +#endif + /* Wrapper to see if two symlinks act the same. */ static void check_same_link (char const *name1, char const *name2) @@ -68,7 +78,7 @@ check_same_link (char const *name1, char const *name2) ASSERT (contents1); ASSERT (contents2); ASSERT (strcmp (contents1, contents2) == 0); - if (!LINK_FOLLOWS_SYMLINKS) + if (EXPECT_LINK_HARDLINKS_SYMLINKS) ASSERT (SAME_INODE (st1, st2)); free (contents1); free (contents2); @@ -108,7 +118,8 @@ main (void) ASSERT (mkdir (BASE "sub1", 0700) == 0); ASSERT (mkdir (BASE "sub2", 0700) == 0); ASSERT (close (creat (BASE "00", 0600)) == 0); - cwd = xgetcwd (); + cwd = getcwd (NULL, 0); + ASSERT (cwd); dfd = open (BASE "sub1", O_RDONLY); ASSERT (0 <= dfd); @@ -129,9 +140,11 @@ main (void) for (i = 0; i < 32; i++) { int fd1 = (i & 8) ? dfd : AT_FDCWD; - char *file1 = file_name_concat ((i & 4) ? ".." : cwd, BASE "xx", NULL); + char *file1 = mfile_name_concat ((i & 4) ? ".." : cwd, BASE "xx", NULL); int fd2 = (i & 2) ? dfd : AT_FDCWD; - char *file2 = file_name_concat ((i & 1) ? ".." : cwd, BASE "xx", NULL); + char *file2 = mfile_name_concat ((i & 1) ? ".." : cwd, BASE "xx", NULL); + ASSERT (file1); + ASSERT (file2); flag = (i & 0x10 ? AT_SYMLINK_FOLLOW : 0); ASSERT (sprintf (strchr (file1, '\0') - 2, "%02d", i) == 2); @@ -180,7 +193,7 @@ main (void) ASSERT (errno == EEXIST || errno == EPERM || errno == EACCES); errno = 0; ASSERT (linkat (dfd, BASE "link1", dfd, BASE "sub1/", 0) == -1); - ASSERT (errno == EEXIST); + ASSERT (errno == EEXIST || errno == ENOTDIR); errno = 0; ASSERT (linkat (dfd, BASE "link1", dfd, BASE "sub1", AT_SYMLINK_FOLLOW) == -1);