AcePerl
view release on metacpan or search on metacpan
acelib/messubs.c view on Meta::CPAN
/* Check arguments. */
if (format == NULL)
{
fprintf(stderr, "uMessFormat() : "
"invalid call, no format string.\n") ;
invokeDebugger();
exit (EXIT_FAILURE);
}
if (prefix == NULL)
prefix_len = 0 ;
else
{
prefix_len = strlen(prefix) ;
if ((prefix_len + 1) > PREFIXSIZE)
{
fprintf (stderr, "uMessFormat() : "
"prefix string is too long.\n") ;
invokeDebugger();
exit (EXIT_FAILURE);
}
}
/* If they supply their own buffer to receive the formatted
message then use this, otherwise use the global messbuf buffer. */
if (buffer != NULL)
{
buf_ptr = buffer ;
buf_len = buflen ;
if (buf_len == 0)
{
fprintf (stderr, "uMessFormat() : "
"zero length buffer supplied for message format.\n") ;
invokeDebugger();
exit (EXIT_FAILURE);
}
}
else
{
buf_ptr = &messbuf[0] ;
buf_len = BUFSIZE ;
}
/* Add the prefix if there is one. */
if (prefix != NULL)
{
if (strcpy (buf_ptr, prefix) == NULL)
{
fprintf (stderr, "uMessFormat() : strcpy failed\n") ;
invokeDebugger();
exit (EXIT_FAILURE);
}
}
/* CHECK PERFORMANCE ISSUES....how is database dumped/logged. */
/* Fred has suggested that we could do a vprintf to /dev/null and see how */
/* many bytes that is then we could get away from a fixed internal buffer */
/* at all....but watch out, if messdump say is in a tight loop then this */
/* will kill performance... */
/* We could add a #define to allow a check to be included for debug code. */
/* */
/* Do the format. */
#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) ;
}
( run in 0.674 second using v1.01-cache-2.11-cpan-364913b4093 )