Skip to content
Snippets Groups Projects
Commit 76f2a671 authored by Benjamin Couturier's avatar Benjamin Couturier
Browse files

Store Csec error in a per thread buffer

parent 070f3924
Branches
Tags
No related merge requests found
......@@ -15,60 +15,45 @@ static char sccsid[] = "@(#)Csec_errmsg.c,v 1.1 2004/01/12 10:31:40 CERN IT/ADC/
#include "Csec.h"
/* Csec_seterrbuf - set receiving buffer for error messages */
/* Csec_errmsg - send error message to error buffer in per-thread structure */
int DLL_DECL
Csec_seterrbuf(char *buffer, int buflen)
{
struct Csec_api_thread_info *thip;
if (Csec_apiinit (&thip))
return (-1);
thip->errbufp = buffer;
thip->errbuflen = buflen;
return (0);
Csec_errmsg(char *func, char *msg, ...) {
va_list args;
int save_errno;
struct Csec_api_thread_info *thip;
int funlen=0;
save_errno = errno;
if (Csec_apiinit (&thip))
return (-1);
va_start (args, msg);
if (func) {
snprintf (thip->errbuf, ERRBUFSIZE, "%s: ", func);
}
funlen = strlen(thip->errbuf);
vsnprintf (thip->errbuf + funlen, ERRBUFSIZE - funlen -1, msg, args);
thip->errbuf[ERRBUFSIZE] = '\0';
Csec_trace("ERROR", "%s\n", thip->errbuf);
errno = save_errno;
return (0);
}
/* Csec_errmsg - send error message to user defined client buffer or to stderr */
int DLL_DECL
Csec_errmsg(char *func, char *msg, ...)
{
va_list args;
char prtbuf[PRTBUFSZ];
int save_errno;
struct Csec_api_thread_info *thip;
int funlen=0;
save_errno = errno;
if (Csec_apiinit (&thip))
return (-1);
va_start (args, msg);
if (func)
snprintf (prtbuf, PRTBUFSZ, "%s: ", func);
else
*prtbuf = '\0';
funlen = strlen(prtbuf);
/* Csec_errmsg - send error message to user defined client buffer or to stderr */
char *Csec_geterrmsg() {
vsnprintf (prtbuf + funlen, PRTBUFSZ - funlen -1, msg, args);
prtbuf[PRTBUFSZ] = '\0';
if (thip->errbufp) {
if (strlen (prtbuf) < thip->errbuflen) {
strcpy (thip->errbufp, prtbuf);
} else {
strncpy (thip->errbufp, prtbuf, thip->errbuflen - 2);
thip->errbufp[thip->errbuflen-2] = '\n';
thip->errbufp[thip->errbuflen-1] = '\0';
}
} else {
fprintf (stderr, "%s\n", prtbuf);
}
struct Csec_api_thread_info *thip;
if (Csec_apiinit (&thip))
return NULL;
return thip->errbuf;
Csec_trace("ERROR", "%s\n", prtbuf);
errno = save_errno;
return (0);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment