test-exclude.c: remove unmatched #endif
[gnulib.git] / tests / test-linkat.c
index 11233fe..8d179e2 100644 (file)
@@ -1,5 +1,5 @@
 /* Tests of linkat.
-   Copyright (C) 2009 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
 
 #include <unistd.h>
 
+#include "signature.h"
+SIGNATURE_CHECK (linkat, int, (int, char const *, int, char const *, int));
+
 #include <fcntl.h>
 #include <errno.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/stat.h>
 
 #include "areadlink.h"
 #include "filenamecat.h"
 #include "same-inode.h"
 #include "xgetcwd.h"
-
-#define ASSERT(expr) \
-  do                                                                         \
-    {                                                                        \
-      if (!(expr))                                                           \
-        {                                                                    \
-          fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__);  \
-          fflush (stderr);                                                   \
-          abort ();                                                          \
-        }                                                                    \
-    }                                                                        \
-  while (0)
+#include "ignore-value.h"
+#include "macros.h"
 
 #define BASE "test-linkat.t"
 
@@ -59,6 +53,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)
@@ -74,7 +79,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);
@@ -89,7 +94,7 @@ main (void)
   int result;
 
   /* Clean up any trash from prior testsuite runs.  */
-  ASSERT (system ("rm -rf " BASE "*") == 0);
+  ignore_value (system ("rm -rf " BASE "*"));
 
   /* Test basic link functionality, without mentioning symlinks.  */
   result = test_link (do_link, true);
@@ -186,7 +191,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);