autoupdate
[gnulib.git] / tests / test-stat.c
index 337c819..b59dbf4 100644 (file)
@@ -1,5 +1,5 @@
 /* Tests of stat.
-   Copyright (C) 2009 Free Software Foundation, Inc.
+   Copyright (C) 2009-2013 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 <sys/stat.h>
 
+/* Caution: stat may be a function-like macro.  Although this
+   signature check must pass, it may be the signature of the real (and
+   broken) stat rather than rpl_stat.  Most code should not use the
+   address of stat.  */
+#include "signature.h"
+SIGNATURE_CHECK (stat, int, (char const *, struct stat *));
+
 #include <fcntl.h>
 #include <errno.h>
+#include <stdbool.h>
 #include <stdio.h>
-#include <stdlib.h>
 #include <unistd.h>
 
-#include "pathmax.h"
 #include "same-inode.h"
-
-#define ASSERT(expr) \
-  do                                                                         \
-    {                                                                        \
-      if (!(expr))                                                           \
-       {                                                                    \
-         fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__);  \
-         fflush (stderr);                                                   \
-         abort ();                                                          \
-       }                                                                    \
-    }                                                                        \
-  while (0)
+#include "macros.h"
 
 #define BASE "test-stat.t"
 
-int
-main ()
-{
-  struct stat st1;
-  struct stat st2;
-  char cwd[PATH_MAX];
-
-  ASSERT (getcwd (cwd, PATH_MAX) == cwd);
-  ASSERT (stat (".", &st1) == 0);
-  ASSERT (stat ("./", &st2) == 0);
-  ASSERT (SAME_INODE (st1, st2));
-  ASSERT (stat (cwd, &st2) == 0);
-  ASSERT (SAME_INODE (st1, st2));
-  ASSERT (stat ("/", &st1) == 0);
-  ASSERT (stat ("///", &st2) == 0);
-  ASSERT (SAME_INODE (st1, st2));
+#include "test-stat.h"
 
-  errno = 0;
-  ASSERT (stat ("", &st1) == -1);
-  ASSERT (errno == ENOENT);
-  errno = 0;
-  ASSERT (stat ("nosuch", &st1) == -1);
-  ASSERT (errno == ENOENT);
-  errno = 0;
-  ASSERT (stat ("nosuch/", &st1) == -1);
-  ASSERT (errno == ENOENT);
-
-  ASSERT (close (creat (BASE "file", 0600)) == 0);
-  ASSERT (stat (BASE "file", &st1) == 0);
-  errno = 0;
-  ASSERT (stat (BASE "file/", &st1) == -1);
-  ASSERT (errno == ENOTDIR);
-  ASSERT (unlink (BASE "file") == 0);
+/* Wrapper around stat, which works even if stat is a function-like
+   macro, where test_stat_func(stat) would do the wrong thing.  */
+static int
+do_stat (char const *name, struct stat *st)
+{
+  return stat (name, st);
+}
 
-  return 0;
+int
+main (void)
+{
+  return test_stat_func (do_stat, true);
 }