1*739b7041Schristos# intdiv0.m4 serial 1 (gettext-0.11.3) 2*739b7041Schristosdnl Copyright (C) 2002 Free Software Foundation, Inc. 3*739b7041Schristosdnl This file is free software; the Free Software Foundation 4*739b7041Schristosdnl gives unlimited permission to copy and/or distribute it, 5*739b7041Schristosdnl with or without modifications, as long as this notice is preserved. 6*739b7041Schristos 7*739b7041Schristosdnl From Bruno Haible. 8*739b7041Schristos 9*739b7041SchristosAC_DEFUN([gt_INTDIV0], 10*739b7041Schristos[ 11*739b7041Schristos AC_REQUIRE([AC_PROG_CC])dnl 12*739b7041Schristos AC_REQUIRE([AC_CANONICAL_HOST])dnl 13*739b7041Schristos 14*739b7041Schristos AC_CACHE_CHECK([whether integer division by zero raises SIGFPE], 15*739b7041Schristos gt_cv_int_divbyzero_sigfpe, 16*739b7041Schristos [ 17*739b7041Schristos AC_TRY_RUN([ 18*739b7041Schristos#include <stdlib.h> 19*739b7041Schristos#include <signal.h> 20*739b7041Schristos 21*739b7041Schristosstatic void 22*739b7041Schristos#ifdef __cplusplus 23*739b7041Schristossigfpe_handler (int sig) 24*739b7041Schristos#else 25*739b7041Schristossigfpe_handler (sig) int sig; 26*739b7041Schristos#endif 27*739b7041Schristos{ 28*739b7041Schristos /* Exit with code 0 if SIGFPE, with code 1 if any other signal. */ 29*739b7041Schristos exit (sig != SIGFPE); 30*739b7041Schristos} 31*739b7041Schristos 32*739b7041Schristosint x = 1; 33*739b7041Schristosint y = 0; 34*739b7041Schristosint z; 35*739b7041Schristosint nan; 36*739b7041Schristos 37*739b7041Schristosint main () 38*739b7041Schristos{ 39*739b7041Schristos signal (SIGFPE, sigfpe_handler); 40*739b7041Schristos/* IRIX and AIX (when "xlc -qcheck" is used) yield signal SIGTRAP. */ 41*739b7041Schristos#if (defined (__sgi) || defined (_AIX)) && defined (SIGTRAP) 42*739b7041Schristos signal (SIGTRAP, sigfpe_handler); 43*739b7041Schristos#endif 44*739b7041Schristos/* Linux/SPARC yields signal SIGILL. */ 45*739b7041Schristos#if defined (__sparc__) && defined (__linux__) 46*739b7041Schristos signal (SIGILL, sigfpe_handler); 47*739b7041Schristos#endif 48*739b7041Schristos 49*739b7041Schristos z = x / y; 50*739b7041Schristos nan = y / y; 51*739b7041Schristos exit (1); 52*739b7041Schristos} 53*739b7041Schristos], gt_cv_int_divbyzero_sigfpe=yes, gt_cv_int_divbyzero_sigfpe=no, 54*739b7041Schristos [ 55*739b7041Schristos # Guess based on the CPU. 56*739b7041Schristos case "$host_cpu" in 57*739b7041Schristos alpha* | i[34567]86 | m68k | s390*) 58*739b7041Schristos gt_cv_int_divbyzero_sigfpe="guessing yes";; 59*739b7041Schristos *) 60*739b7041Schristos gt_cv_int_divbyzero_sigfpe="guessing no";; 61*739b7041Schristos esac 62*739b7041Schristos ]) 63*739b7041Schristos ]) 64*739b7041Schristos case "$gt_cv_int_divbyzero_sigfpe" in 65*739b7041Schristos *yes) value=1;; 66*739b7041Schristos *) value=0;; 67*739b7041Schristos esac 68*739b7041Schristos AC_DEFINE_UNQUOTED(INTDIV0_RAISES_SIGFPE, $value, 69*739b7041Schristos [Define if integer division by zero raises signal SIGFPE.]) 70*739b7041Schristos]) 71