Home | History | Annotate | Download | only in m4
      1 dnl AC_FUNC_SCANF_CAN_MALLOC macro
      2 dnl
      3 dnl (c) Finn Thain 2006
      4 dnl Copying and distribution of this file, with or without modification,
      5 dnl are permitted in any medium without royalty provided the copyright
      6 dnl notice and this notice are preserved.
      7 
      8 # AC_FUNC_SCANF_CAN_MALLOC()
      9 # --------------------------------------
     10 AC_DEFUN([AC_FUNC_SCANF_CAN_MALLOC],
     11   [ AC_CHECK_HEADERS([stdlib.h])
     12     AC_CACHE_CHECK([whether scanf can malloc], [ac_scanf_can_malloc],
     13     [ AC_RUN_IFELSE(
     14       [ AC_LANG_PROGRAM(
     15         [
     16 #include <stdio.h>
     17 #if STDC_HEADERS || HAVE_STDLIB_H
     18 #include <stdlib.h>
     19 #endif
     20         ], [
     21   union { float f; char *p; } u;
     22   char *p;
     23   u.f = 0;
     24   char *scan_this = "56789";
     25   int matched = sscanf(scan_this, "%as", &u);
     26   if(matched < 1) return 1; /* shouldn't happens */
     27   if(u.f == (float)56789) return 2;
     28 
     29   p = u.p;
     30   while(*scan_this && *p == *scan_this) {
     31     ++p;
     32     ++scan_this;
     33   };
     34   free(u.p);
     35   if(*scan_this == 0) return 0;
     36   return 3;
     37         ])
     38       ],
     39       [ac_scanf_can_malloc=yes],
     40       [ac_scanf_can_malloc=no],
     41       [
     42 case $host_alias in
     43   *-*-linux* ) ac_scanf_can_malloc=yes ;;
     44   *-*-solaris* ) ac_scanf_can_malloc=no ;;
     45   *-*-darwin* ) ac_scanf_can_malloc=no ;;
     46   * ) ac_scanf_can_malloc=no ;;
     47 esac
     48       ])
     49     ])
     50 if test x$ac_scanf_can_malloc = "xyes"; then
     51   AC_DEFINE([SCANF_CAN_MALLOC], 1, [Define to 1 if the scanf %a conversion format mallocs a buffer. Undefine if %a format denotes a float.])
     52 fi
     53   ])
     54