1dnl AC_FUNC_SCANF_CAN_MALLOC macro 2dnl 3dnl (c) Finn Thain 2006 4dnl Copying and distribution of this file, with or without modification, 5dnl are permitted in any medium without royalty provided the copyright 6dnl notice and this notice are preserved. 7 8# AC_FUNC_SCANF_CAN_MALLOC() 9# -------------------------------------- 10AC_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 [ 42case $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 ;; 47esac 48 ]) 49 ]) 50if 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.]) 52fi 53 ]) 54