Fix up mix of man(7)/mdoc(7).
[netbsd-mini2440.git] / regress / lib / libc / siginfo / sigfpe / sigfpe.c
blobc771877a2cc2ae3a167c291618b83f18ce2c6df9
1 /* $NetBSD: sigfpe.c,v 1.1 2009/02/17 19:05:22 christos Exp $ */
3 #include <sys/time.h>
4 #include <sys/ucontext.h>
6 #include <assert.h>
7 #include <signal.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #ifndef __vax__
12 #include <ieeefp.h>
13 #endif
15 sig_atomic_t z = 0;
17 void
18 sigfpe(int signo, siginfo_t *info, void *ptr)
20 #ifdef DEBUG
21 printf("%d %p %p\n", signo, info, ptr);
22 if (info != NULL) {
23 printf("si_signo=%d\n", info->si_signo);
24 printf("si_errno=%d\n", info->si_errno);
25 printf("si_code=%d\n", info->si_code);
26 printf("si_value.sival_int=%d\n", info->si_value.sival_int);
28 if (ptr != NULL) {
29 ucontext_t *ctx = ptr;
30 int i;
31 mcontext_t *mc = &ctx->uc_mcontext;
32 printf("uc_flags 0x%x\n", ctx->uc_flags);
33 printf("uc_link %p\n", ctx->uc_link);
34 for (i = 0; i < sizeof(ctx->uc_sigmask.__bits) /
35 sizeof(ctx->uc_sigmask.__bits[0]); i++)
36 printf("uc_sigmask[%d] 0x%x\n", i,
37 ctx->uc_sigmask.__bits[i]);
38 printf("uc_stack %p %lu 0x%x\n", ctx->uc_stack.ss_sp,
39 (unsigned long)ctx->uc_stack.ss_size,
40 ctx->uc_stack.ss_flags);
41 for (i = 0; i < sizeof(mc->__gregs)/sizeof(mc->__gregs[0]); i++)
42 printf("uc_mcontext.greg[%d] 0x%x\n", i,
43 mc->__gregs[i]);
45 #endif
46 assert(z++ == 0);
47 assert(info->si_signo == SIGFPE);
48 assert(info->si_code == FPE_FLTDIV);
49 assert(info->si_errno == 0);
52 int
53 main(void)
55 struct sigaction sa;
56 double d = strtod("0", NULL);
58 sa.sa_flags = SA_SIGINFO;
59 sa.sa_sigaction = sigfpe;
60 sigemptyset(&sa.sa_mask);
61 sigaction(SIGFPE, &sa, NULL);
62 #ifndef __vax__
63 fpsetmask(FP_X_INV|FP_X_DZ|FP_X_OFL|FP_X_UFL|FP_X_IMP);
64 #endif
65 printf("%g\n", 1 / d);
66 assert(z == 1);
67 return 0;