Paste number 48267: SIGFPE handler on FreeBSD

Paste number 48267: SIGFPE handler on FreeBSD
Pasted by: housel
1 year, 2 weeks ago
#dylan | Context in IRC logs
Paste contents:
Raw Source | XML | Display As
#include <sys/types.h>
#include <sys/signal.h>
#include <ucontext.h>
#include <ieeefp.h>
#include <fenv.h>

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

static int zeroi(void);

void fpe_handler(int signal, struct __siginfo *si, void *sc)
{
  printf("fpe_handler signal=%d code=%d addr=%p\n",
         signal, si->si_code, si->si_addr);
  fflush(stdout);
  _exit(1);
}

int main(int argc, char *argv) {
  struct sigaction sa, osa;
  sa.sa_flags = SA_SIGINFO;
  sa.sa_sigaction = fpe_handler;
  sigfillset(&sa.sa_mask);
  if (sigaction(SIGFPE, &sa, &osa) != 0) {
    perror("sigaction");
    return 1;
  }
  
  printf("%d\n", 2000 / zeroi());

  return 0;
}

static int zeroi(void) {
  return 0;
}

This paste has no annotations.

Colorize as:
Show Line Numbers

Ads absolutely not by Google

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.