AcePerl

 view release on metacpan or  search on metacpan

acelib/messubs.c  view on Meta::CPAN

#ifdef SUN
  {
    char *return_str;

    /* NOTE, that SUNs vsprintf returns a char* */
    return_str = vsprintf((buf_ptr + prefix_len), format, args) + prefix_len + 1 ;
    
    /* Check the result. */
    if (!return_str)
      {
	fprintf(stderr, "uMessFormat() : "
		"vsprintf failed: %s\n", messSysErrorText()) ;
	invokeDebugger();
	exit (EXIT_FAILURE);
      }
    else if (strlen(return_str) > buf_len)
      {
	fprintf (stderr, "uMessFormat() : "
		 "messubs internal buffer size (%d) exceeded, "
		 "a total of %ld bytes were written\n",
		 buf_len, strlen(return_str)) ;  
	invokeDebugger();
	exit (EXIT_FAILURE);
      }
  }
#else  /* !SUN */
  {
    /* all other System's vsprintf returns an integer, of how many bytes have been written */
    int num_bytes = vsprintf((buf_ptr + prefix_len), format, args) + prefix_len + 1 ;
    
    /* Check the result.                                                       */
    if (num_bytes < 0)
      {
	fprintf(stderr, "uMessFormat() : "
		"vsprintf failed: %s\n", messSysErrorText()) ;
	invokeDebugger();
	exit (EXIT_FAILURE);
      }
    else if (num_bytes > buf_len)
      {
	fprintf (stderr, "uMessFormat() : "
		 "messubs internal buffer size (%d) exceeded, "
		 "a total of %d bytes were written\n",
		 buf_len, num_bytes) ;  
	invokeDebugger();
	exit (EXIT_FAILURE);
      }
  }
#endif /* !SUN */

  return(buf_ptr) ;
  }


/********************** crash file/line info routines ************************/
/* When the acedb needs to crash because there has been an unrecoverable     */
/* error we want to output the file and line number of the code that         */
/* detected the error. Here are the functions to do it.                      */
/*                                                                           */

/* Applications can optionally initialise the error handling section of the  */
/* message package, currently the program name can be set (argv[0] in the    */
/* main routine) as there is no easy way to get at this at run time except   */
/* from the main.                                                            */
/*                                                                           */
UTIL_FUNC_DEF void messErrorInit(char *progname)
  {

  if (progname != NULL) messageG.progname = strnew(filGetFilename(progname), 0) ;

  return ;
  }

/* This function is called by the messcrash macro which inserts the file and */
/* line information using the __FILE__ & __LINE__ macros.                    */
/*                                                                           */
UTIL_FUNC_DEF void uMessSetErrorOrigin(char *filename, int line_num)
{
  
  assert(filename != NULL && line_num != 0) ;
  
  /* We take the basename here because __FILE__ can be a path rather than    */
  /* just a filename, depending on how a module was compiled.                */
  messageG.filename = strnew(filGetFilename(filename), 0) ;
  
  messageG.line_num = line_num ;
}

/* mieg: protected these func against bad return, was crashing solaris server */
/* Access functions for message error data.                                  */
UTIL_FUNC_DEF char *messGetErrorProgram()
{
  return messageG.progname ?  messageG.progname : "programme_name_unknown"  ;
}  

static char *messGetErrorFile()
{
  return messageG.filename ? messageG.filename  : "file_name_unknown" ; 
}  

static int messGetErrorLine()
{
  return messageG.line_num ;
}  


/*****************************/

/* put "break invokeDebugger" in your favourite debugger init file */

UTIL_FUNC_DEF void invokeDebugger (void) 
{
  static BOOL reentrant = FALSE ;

  if (!reentrant)
    { reentrant = TRUE ;
      messalloccheck() ;
      reentrant = FALSE ;
    }
}



( run in 2.673 seconds using v1.01-cache-2.11-cpan-98e64b0badf )