Better handling of collision with AIX stpncpy() function.
[gnulib.git] / lib / vasnprintf.c
index 994f993..9c701f1 100644 (file)
 #include "printf-parse.h"
 
 /* For those losing systems which don't have 'alloca' we have to add
-   some additional code emulating it.  */ 
-#ifdef HAVE_ALLOCA 
+   some additional code emulating it.  */
+#ifdef HAVE_ALLOCA
 # define freea(p) /* nothing */
 #else
-# define alloca(n) malloc (n) 
-# define freea(p) free (p) 
+# define alloca(n) malloc (n)
+# define freea(p) free (p)
+#endif
+
+#ifdef HAVE_WCHAR_T
+# ifdef HAVE_WCSLEN
+#  define local_wcslen wcslen
+# else
+   /* Solaris 2.5.1 has wcslen() in a separate library libw.so. To avoid
+      a dependency towards this library, here is a local substitute.  */
+static size_t
+local_wcslen (const wchar_t *s)
+{
+  const wchar_t *ptr;
+
+  for (ptr = s; *ptr != (wchar_t) 0; ptr++)
+    ;
+  return ptr - s;
+}
+# endif
 #endif
 
 char *
@@ -368,7 +386,7 @@ vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args)
 # ifdef HAVE_WCHAR_T
                      if (type == TYPE_WIDE_STRING)
                        tmp_length =
-                         wcslen (a.arg[dp->arg_index].a.a_wide_string)
+                         local_wcslen (a.arg[dp->arg_index].a.a_wide_string)
                          * MB_CUR_MAX;
                      else
 # endif
@@ -509,7 +527,7 @@ vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args)
                    retcount = 0;
 
 #if HAVE_SNPRINTF
-#define SNPRINTF_BUF(arg) \
+# define SNPRINTF_BUF(arg) \
                    switch (prefix_count)                                   \
                      {                                                     \
                      case 0:                                               \
@@ -529,7 +547,7 @@ vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args)
                        abort ();                                           \
                      }
 #else
-#define SNPRINTF_BUF(arg) \
+# define SNPRINTF_BUF(arg) \
                    switch (prefix_count)                                   \
                      {                                                     \
                      case 0:                                               \