1 |
/* |
2 |
* i-scream libstatgrab |
3 |
* http://www.i-scream.org |
4 |
* Copyright (C) 2000-2004 i-scream |
5 |
* |
6 |
* This library is free software; you can redistribute it and/or |
7 |
* modify it under the terms of the GNU Lesser General Public |
8 |
* License as published by the Free Software Foundation; either |
9 |
* version 2.1 of the License, or (at your option) any later version. |
10 |
* |
11 |
* This library is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 |
* Lesser General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU Lesser General Public |
17 |
* License along with this library; if not, write to the Free Software |
18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
19 |
* 02111-1307 USA |
20 |
* |
21 |
* $Id: error.c,v 1.9 2004/04/07 21:47:50 tdb Exp $ |
22 |
*/ |
23 |
|
24 |
#ifdef HAVE_CONFIG_H |
25 |
#include "config.h" |
26 |
#endif |
27 |
|
28 |
#include <stdlib.h> |
29 |
|
30 |
#include "statgrab.h" |
31 |
|
32 |
static sg_error error = SG_ERROR_NONE; |
33 |
#define ERROR_ARG_MAX 256 |
34 |
static char error_arg[ERROR_ARG_MAX]; |
35 |
|
36 |
void sg_set_error(sg_error code, const char *arg) { |
37 |
error = code; |
38 |
if (arg != NULL) { |
39 |
sg_strlcpy(error_arg, arg, sizeof error_arg); |
40 |
} |
41 |
else { |
42 |
/* FIXME is this the best idea? */ |
43 |
error_arg[0] = '\0'; |
44 |
} |
45 |
} |
46 |
|
47 |
sg_error sg_get_error() { |
48 |
return error; |
49 |
} |
50 |
|
51 |
const char *sg_get_error_arg() { |
52 |
return error_arg; |
53 |
} |
54 |
|
55 |
const char *sg_str_error(sg_error code) { |
56 |
switch (code) { |
57 |
case SG_ERROR_NONE: |
58 |
return "no error"; |
59 |
case SG_ERROR_ASPRINTF: |
60 |
return "asprintf failed"; |
61 |
case SG_ERROR_DEVSTAT_GETDEVS: |
62 |
return "devstat_getdevs failed"; |
63 |
case SG_ERROR_DEVSTAT_SELECTDEVS: |
64 |
return "devstat_selectdevs failed"; |
65 |
case SG_ERROR_ENOENT: |
66 |
return "system call received ENOENT"; |
67 |
case SG_ERROR_GETIFADDRS: |
68 |
return "getifaddress failed"; |
69 |
case SG_ERROR_GETMNTINFO: |
70 |
return "getmntinfo failed"; |
71 |
case SG_ERROR_GETPAGESIZE: |
72 |
return "getpagesize failed"; |
73 |
case SG_ERROR_KSTAT_DATA_LOOKUP: |
74 |
return "kstat_data_lookup failed"; |
75 |
case SG_ERROR_KSTAT_LOOKUP: |
76 |
return "kstat_lookup failed"; |
77 |
case SG_ERROR_KSTAT_OPEN: |
78 |
return "kstat_open failed"; |
79 |
case SG_ERROR_KSTAT_READ: |
80 |
return "kstat_read failed"; |
81 |
case SG_ERROR_KVM_GETSWAPINFO: |
82 |
return "kvm_getswapinfo failed"; |
83 |
case SG_ERROR_KVM_OPENFILES: |
84 |
return "kvm_openfiles failed"; |
85 |
case SG_ERROR_MALLOC: |
86 |
return "malloc failed"; |
87 |
case SG_ERROR_OPEN: |
88 |
return "failed to open file"; |
89 |
case SG_ERROR_OPENDIR: |
90 |
return "failed to open directory"; |
91 |
case SG_ERROR_PARSE: |
92 |
return "failed to parse input"; |
93 |
case SG_ERROR_SETEGID: |
94 |
return "setegid failed"; |
95 |
case SG_ERROR_SETEUID: |
96 |
return "seteuid failed"; |
97 |
case SG_ERROR_SETMNTENT: |
98 |
return "setmntent failed"; |
99 |
case SG_ERROR_SOCKET: |
100 |
return "socket failed"; |
101 |
case SG_ERROR_SWAPCTL: |
102 |
return "swapctl failed"; |
103 |
case SG_ERROR_SYSCONF: |
104 |
return "sysconf failed"; |
105 |
case SG_ERROR_SYSCTL: |
106 |
return "sysctl failed"; |
107 |
case SG_ERROR_SYSCTLBYNAME: |
108 |
return "sysctlbyname failed"; |
109 |
case SG_ERROR_SYSCTLNAMETOMIB: |
110 |
return "sysctlnametomib failed"; |
111 |
case SG_ERROR_UNAME: |
112 |
return "uname failed"; |
113 |
case SG_ERROR_UNSUPPORTED: |
114 |
return "unsupported function"; |
115 |
case SG_ERROR_XSW_VER_MISMATCH: |
116 |
return "XSW version mismatch"; |
117 |
} |
118 |
return "unknown error"; |
119 |
} |
120 |
|