ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/libstatgrab/src/libstatgrab/error.c
(Generate patch)

Comparing projects/libstatgrab/src/libstatgrab/error.c (file contents):
Revision 1.5 by tdb, Wed Apr 7 14:53:40 2004 UTC vs.
Revision 1.18 by tdb, Sun Oct 3 18:35:57 2010 UTC

# Line 26 | Line 26
26   #endif
27  
28   #include <stdlib.h>
29 + #include <string.h>
30 + #include <errno.h>
31  
32   #include "statgrab.h"
33 + #include "tools.h"
34  
35   static sg_error error = SG_ERROR_NONE;
36 + #define ERROR_ARG_MAX 256
37 + static char error_arg[ERROR_ARG_MAX];
38 + static int errno_value = 0;
39  
40   void sg_set_error(sg_error code, const char *arg) {
41 +        errno_value = 0;
42          error = code;
43 <        /* FIXME do something with arg */
43 >        if (arg != NULL) {
44 >                sg_strlcpy(error_arg, arg, sizeof error_arg);
45 >        }
46 >        else {
47 >                /* FIXME is this the best idea? */
48 >                error_arg[0] = '\0';
49 >        }
50   }
51  
52 + void sg_set_error_with_errno(sg_error code, const char *arg) {
53 +        sg_set_error(code, arg);
54 +        errno_value = errno;
55 + }
56 +
57   sg_error sg_get_error() {
58          return error;
59   }
60  
61 + const char *sg_get_error_arg() {
62 +        return error_arg;
63 + }
64 +
65 + int sg_get_error_errno() {
66 +        return errno_value;
67 + }
68 +
69   const char *sg_str_error(sg_error code) {
70          switch (code) {
71          case SG_ERROR_NONE:
72                  return "no error";
73 +        case SG_ERROR_ASPRINTF:
74 +                return "asprintf failed";
75 +        case SG_ERROR_DEVSTAT_GETDEVS:
76 +                return "devstat_getdevs failed";
77 +        case SG_ERROR_DEVSTAT_SELECTDEVS:
78 +                return "devstat_selectdevs failed";
79 +        case SG_ERROR_ENOENT:
80 +                return "system call received ENOENT";
81 +        case SG_ERROR_GETIFADDRS:
82 +                return "getifaddress failed";
83 +        case SG_ERROR_GETMNTINFO:
84 +                return "getmntinfo failed";
85 +        case SG_ERROR_GETPAGESIZE:
86 +                return "getpagesize failed";
87 +        case SG_ERROR_HOST:
88 +                return "gather host information faile";
89 +        case SG_ERROR_KSTAT_DATA_LOOKUP:
90 +                return "kstat_data_lookup failed";
91 +        case SG_ERROR_KSTAT_LOOKUP:
92 +                return "kstat_lookup failed";
93 +        case SG_ERROR_KSTAT_OPEN:
94 +                return "kstat_open failed";
95 +        case SG_ERROR_KSTAT_READ:
96 +                return "kstat_read failed";
97 +        case SG_ERROR_KVM_GETSWAPINFO:
98 +                return "kvm_getswapinfo failed";
99 +        case SG_ERROR_KVM_OPENFILES:
100 +                return "kvm_openfiles failed";
101          case SG_ERROR_MALLOC:
102                  return "malloc failed";
49        case SG_ERROR_KSTAT_OPEN:
50                return "failed to open kstat";
103          case SG_ERROR_OPEN:
104                  return "failed to open file";
105 <        case SG_ERROR_SYSCTLBYNAME:
106 <                return "sysctlbyname failed";
105 >        case SG_ERROR_OPENDIR:
106 >                return "failed to open directory";
107          case SG_ERROR_PARSE:
108                  return "failed to parse input";
109 <        default:
110 <                return "unknown error";
109 >        case SG_ERROR_SETEGID:
110 >                return "setegid failed";
111 >        case SG_ERROR_SETEUID:
112 >                return "seteuid failed";
113 >        case SG_ERROR_SETMNTENT:
114 >                return "setmntent failed";
115 >        case SG_ERROR_SOCKET:
116 >                return "socket failed";
117 >        case SG_ERROR_SWAPCTL:
118 >                return "swapctl failed";
119 >        case SG_ERROR_SYSCONF:
120 >                return "sysconf failed";
121 >        case SG_ERROR_SYSCTL:
122 >                return "sysctl failed";
123 >        case SG_ERROR_SYSCTLBYNAME:
124 >                return "sysctlbyname failed";
125 >        case SG_ERROR_SYSCTLNAMETOMIB:
126 >                return "sysctlnametomib failed";
127 >        case SG_ERROR_UNAME:
128 >                return "uname failed";
129 >        case SG_ERROR_UNSUPPORTED:
130 >                return "unsupported function";
131 >        case SG_ERROR_XSW_VER_MISMATCH:
132 >                return "XSW version mismatch";
133 >        case SG_ERROR_PSTAT:
134 >                return "pstat failed";
135 >        case SG_ERROR_PDHOPEN:
136 >                return "PDH open failed";
137 >        case SG_ERROR_PDHCOLLECT:
138 >                return "PDH snapshot failed";
139 >        case SG_ERROR_PDHADD:
140 >                return "PDH add counter failed";
141 >        case SG_ERROR_PDHREAD:
142 >                return "PDH read counter failed";
143 >        case SG_ERROR_DEVICES:
144 >                return "failed to get device list";
145 >        case SG_ERROR_PERMISSION:
146 >                return "access violation";
147 >        case SG_ERROR_DISKINFO:
148 >                return "disk function failed";
149 >        case SG_ERROR_MEMSTATUS:
150 >                return "memory status failed";
151 >        case SG_ERROR_GETMSG:
152 >                return "getmsg failed";
153 >        case SG_ERROR_PUTMSG:
154 >                return "putmsg failed";
155          }
156 +        return "unknown error";
157   }
158  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines