#include <stdio.h>
#include <signal.h>
#include <setjmp.h>

static int cant_read_more = 0;
static jmp_buf env;

static void catch_fn(...)
{
   cant_read_more = 1;
   longjmp(env,1);
}


unsigned int  impsaferead(unsigned int from)
{
   void *sig_BUS,*sig_SEGV;
   char c;

#ifdef TRACE
   fprintf(stderr,"Starting read at: 0x%8.8x\n",from);
#endif
   cant_read_more = 0;
   sig_BUS = (void *)sigset(SIGBUS,(void (*)(int)) catch_fn);
   sig_SEGV = (void *)sigset(SIGSEGV,(void (*)(int)) catch_fn);
   if (setjmp(env)) {
      return 1;
   } else c = *(char *)from;
   (void) sigset(SIGBUS,sig_BUS);
   (void) sigset(SIGSEGV,sig_SEGV);
#ifdef TRACE
   fprintf(stderr,"   read byte\n");
#endif
   return 0;
}


