]> andersk Git - moira.git/blob - clients/lib/error.c
Heap o' new functionality. Specifically:
[moira.git] / clients / lib / error.c
1 /* $Id$
2  *
3  * mrcl error interface
4  *
5  * Copyright (C) 1999 by the Massachusetts Institute of Technology
6  * For copying and distribution information, please see the file
7  * <mit-copyright.h>.
8  */
9
10 #include <mit-copyright.h>
11 #include <moira.h>
12 #include <mrclient.h>
13 #include "mrclient-internal.h"
14
15 #include <stdarg.h>
16 #include <stdlib.h>
17 #include <stdio.h>
18
19 #include <com_err.h>
20
21 RCSID("$Header$");
22
23 static char *mrcl_message = NULL;
24
25 void mrcl_set_message(char *fmt, ...)
26 {
27   int args, len;
28   char *p;
29   va_list ap;
30
31   free(mrcl_message);
32
33   /* Count "%s"s */
34   for (args = 0, p = strstr(fmt, "%s"); p; p = strstr(p + 2, "%s"))
35     args++;
36
37   /* Measure the output string. */
38   len = strlen(fmt) + 1;
39   va_start(ap, fmt);
40   while (args--)
41     {
42       p = va_arg(ap, char *);
43       len += strlen(p);
44     }
45   va_end(ap);
46
47   /* Malloc and print */
48   mrcl_message = malloc(len);
49   if (mrcl_message)
50     {
51       va_start(ap, fmt);
52       vsprintf(mrcl_message, fmt, ap);
53       va_end(ap);
54     }
55 }
56
57 char *mrcl_get_message(void)
58 {
59   return mrcl_message;
60 }
61
62 void mrcl_clear_message(void)
63 {
64   free(mrcl_message);
65   mrcl_message = NULL;
66 }
67
68 void mrcl_com_err(char *whoami)
69 {
70   if (mrcl_message)
71     com_err(whoami, 0, "%s", mrcl_message);
72 }
This page took 0.040652 seconds and 5 git commands to generate.