Revision 24319,
1.4 KB
checked in by broder, 15 years ago
(diff) |
New Moira snapshot from SVN.
|
Line | |
---|
1 | /* $Id: error.c 3956 2010-01-05 20:56:56Z zacheiss $ |
---|
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 | #include <string.h> |
---|
19 | |
---|
20 | #include <com_err.h> |
---|
21 | |
---|
22 | RCSID("$HeadURL: svn+ssh://svn.mit.edu/moira/trunk/moira/clients/lib/error.c $ $Id: error.c 3956 2010-01-05 20:56:56Z zacheiss $"); |
---|
23 | |
---|
24 | static char *mrcl_message = NULL; |
---|
25 | |
---|
26 | void mrcl_set_message(char *fmt, ...) |
---|
27 | { |
---|
28 | int args, len; |
---|
29 | char *p; |
---|
30 | va_list ap; |
---|
31 | |
---|
32 | free(mrcl_message); |
---|
33 | |
---|
34 | /* Count "%s"s */ |
---|
35 | for (args = 0, p = strstr(fmt, "%s"); p; p = strstr(p + 2, "%s")) |
---|
36 | args++; |
---|
37 | |
---|
38 | /* Measure the output string. */ |
---|
39 | len = strlen(fmt) + 1; |
---|
40 | va_start(ap, fmt); |
---|
41 | while (args--) |
---|
42 | { |
---|
43 | p = va_arg(ap, char *); |
---|
44 | len += strlen(p); |
---|
45 | } |
---|
46 | va_end(ap); |
---|
47 | |
---|
48 | /* Malloc and print */ |
---|
49 | mrcl_message = malloc(len); |
---|
50 | if (mrcl_message) |
---|
51 | { |
---|
52 | va_start(ap, fmt); |
---|
53 | vsprintf(mrcl_message, fmt, ap); |
---|
54 | va_end(ap); |
---|
55 | } |
---|
56 | } |
---|
57 | |
---|
58 | char *mrcl_get_message(void) |
---|
59 | { |
---|
60 | return mrcl_message; |
---|
61 | } |
---|
62 | |
---|
63 | void mrcl_clear_message(void) |
---|
64 | { |
---|
65 | free(mrcl_message); |
---|
66 | mrcl_message = NULL; |
---|
67 | } |
---|
68 | |
---|
69 | void mrcl_com_err(char *whoami) |
---|
70 | { |
---|
71 | if (mrcl_message) |
---|
72 | com_err(whoami, 0, "%s", mrcl_message); |
---|
73 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.