]> granicus.if.org Git - php/commitdiff
Check for C99 conformance of snprintf.
authorMarcus Boerger <helly@php.net>
Wed, 2 Oct 2002 12:52:53 +0000 (12:52 +0000)
committerMarcus Boerger <helly@php.net>
Wed, 2 Oct 2002 12:52:53 +0000 (12:52 +0000)
#This way we force using internal version if a broken library is used.
#E.g. length parameter is broken, return value or default precision wrong.

acinclude.m4
configure.in

index 7f8f57a18186928872694924a593810559bfaffd..01810775be46e93418f2fa42ff4da37b04222ca1 100644 (file)
@@ -1164,7 +1164,7 @@ AC_DEFUN(PHP_MISSING_FCLOSE_DECL,[
 ])
 
 dnl
-dnl Check for broken sprintf()
+dnl Check for broken sprintf(), C99 conformance
 dnl
 AC_DEFUN(PHP_AC_BROKEN_SPRINTF,[
   AC_CACHE_CHECK(whether sprintf is broken, ac_cv_broken_sprintf,[
@@ -1177,9 +1177,42 @@ AC_DEFUN(PHP_AC_BROKEN_SPRINTF,[
     ])
   ])
   if test "$ac_cv_broken_sprintf" = "yes"; then
-    AC_DEFINE(PHP_BROKEN_SPRINTF, 1, [ ])
+    AC_DEFINE(PHP_BROKEN_SPRINTF, 1, [Whether sprintf is C99 conform])
   else
-    AC_DEFINE(PHP_BROKEN_SPRINTF, 0, [ ])
+    AC_DEFINE(PHP_BROKEN_SPRINTF, 0, [Whether sprintf is C99 conform])
+  fi
+])
+
+dnl
+dnl Check for broken snprintf(), C99 conformance
+dnl
+AC_DEFUN(PHP_AC_BROKEN_SNPRINTF,[
+  AC_CACHE_CHECK(whether snprintf is broken, ac_cv_broken_snprintf,[
+    AC_TRY_RUN([
+#define NULL (0L)
+main() {
+       char buf[20];
+       int res = 0;
+       res = res || (snprintf(buf, 2, "marcus") != 6); 
+       res = res || (buf[1] != '\0');
+       res = res || (snprintf(buf, 0, "boerger") != 7);
+       res = res || (buf[0] != 'm');
+       res = res || (snprintf(NULL, 0, "boerger") != 7);
+       res = res || (snprintf(buf, sizeof(buf), "%f", 0.12345678) != 8);
+       exit(res); 
+}
+    ],[
+      ac_cv_broken_snprintf=no
+    ],[
+      ac_cv_broken_snprintf=yes
+    ],[
+      ac_cv_broken_snprintf=no
+    ])
+  ])
+  if test "$ac_cv_broken_snprintf" = "yes"; then
+    AC_DEFINE(PHP_BROKEN_SNPRINTF, 1, [Whether snprintf is C99 conform])
+  else
+    AC_DEFINE(PHP_BROKEN_SNPRINTF, 0, [Whether snprintf is C99 conform])
   fi
 ])
 
index 4f7fc56398040f14c954e65e23023d8a07b30e64..54b393440234c22fc9c9d7273a4bfbd788097f94 100644 (file)
@@ -493,6 +493,7 @@ AC_REPLACE_FUNCS(strlcat strlcpy getopt)
 AC_FUNC_UTIME_NULL
 AC_FUNC_ALLOCA
 PHP_AC_BROKEN_SPRINTF
+PHP_AC_BROKEN_SNPRINTF
 PHP_DECLARED_TIMEZONE
 PHP_TIME_R_TYPE
 PHP_READDIR_R_TYPE