* lib/time_.h: Port to Solaris 8 with Sun Studio 11, using a
[gnulib.git] / tests / test-snprintf.c
index 7b3e9b4..58e3823 100644 (file)
 
 /* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
 
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
+#include <config.h>
 
 #include <stdio.h>
 
 #include <stdlib.h>
 #include <string.h>
 
-#define ASSERT(expr) if (!(expr)) abort ();
+#define ASSERT(expr) \
+  do                                                                        \
+    {                                                                       \
+      if (!(expr))                                                          \
+        {                                                                   \
+          fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
+          abort ();                                                         \
+        }                                                                   \
+    }                                                                       \
+  while (0)
 
 int
 main (int argc, char *argv[])
@@ -41,13 +48,18 @@ main (int argc, char *argv[])
       retval = snprintf (buf, size, "%d", 12345);
       if (size < 6)
        {
+#if CHECK_SNPRINTF_POSIX
          ASSERT (retval < 0 || retval >= size);
+#endif
          if (size > 0)
            {
              ASSERT (memcmp (buf, "12345", size - 1) == 0);
              ASSERT (buf[size - 1] == '\0' || buf[size - 1] == '0' + size);
            }
-         ASSERT (memcmp (buf + size, "DEADBEEF" + size, 8 - size) == 0);
+#if !CHECK_SNPRINTF_POSIX
+         if (size > 0)
+#endif
+           ASSERT (memcmp (buf + size, "DEADBEEF" + size, 8 - size) == 0);
        }
       else
        {