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.1 by tdb, Tue Apr 6 21:38:55 2004 UTC vs.
Revision 1.13 by tdb, Fri Jul 16 15:28:02 2004 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;
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          error = code;
42 +        if (arg != NULL) {
43 +                sg_strlcpy(error_arg, arg, sizeof error_arg);
44 +        }
45 +        else {
46 +                /* FIXME is this the best idea? */
47 +                error_arg[0] = '\0';
48 +        }
49   }
50  
51 + void sg_set_error_with_errno(sg_error code, const char *arg) {
52 +        errno_value = errno;
53 +        sg_set_error(code, arg);
54 + }
55 +
56   sg_error sg_get_error() {
57          return error;
58   }
59  
60 < char *sg_str_error(sg_error code) {
61 <        return NULL;
60 > const char *sg_get_error_arg() {
61 >        return error_arg;
62 > }
63 >
64 > const int sg_get_error_errno() {
65 >        return errno_value;
66 > }
67 >
68 > const char *sg_str_error(sg_error code) {
69 >        switch (code) {
70 >        case SG_ERROR_NONE:
71 >                return "no error";
72 >        case SG_ERROR_ASPRINTF:
73 >                return "asprintf failed";
74 >        case SG_ERROR_DEVSTAT_GETDEVS:
75 >                return "devstat_getdevs failed";
76 >        case SG_ERROR_DEVSTAT_SELECTDEVS:
77 >                return "devstat_selectdevs failed";
78 >        case SG_ERROR_ENOENT:
79 >                return "system call received ENOENT";
80 >        case SG_ERROR_GETIFADDRS:
81 >                return "getifaddress failed";
82 >        case SG_ERROR_GETMNTINFO:
83 >                return "getmntinfo failed";
84 >        case SG_ERROR_GETPAGESIZE:
85 >                return "getpagesize failed";
86 >        case SG_ERROR_KSTAT_DATA_LOOKUP:
87 >                return "kstat_data_lookup failed";
88 >        case SG_ERROR_KSTAT_LOOKUP:
89 >                return "kstat_lookup failed";
90 >        case SG_ERROR_KSTAT_OPEN:
91 >                return "kstat_open failed";
92 >        case SG_ERROR_KSTAT_READ:
93 >                return "kstat_read failed";
94 >        case SG_ERROR_KVM_GETSWAPINFO:
95 >                return "kvm_getswapinfo failed";
96 >        case SG_ERROR_KVM_OPENFILES:
97 >                return "kvm_openfiles failed";
98 >        case SG_ERROR_MALLOC:
99 >                return "malloc failed";
100 >        case SG_ERROR_OPEN:
101 >                return "failed to open file";
102 >        case SG_ERROR_OPENDIR:
103 >                return "failed to open directory";
104 >        case SG_ERROR_PARSE:
105 >                return "failed to parse input";
106 >        case SG_ERROR_SETEGID:
107 >                return "setegid failed";
108 >        case SG_ERROR_SETEUID:
109 >                return "seteuid failed";
110 >        case SG_ERROR_SETMNTENT:
111 >                return "setmntent failed";
112 >        case SG_ERROR_SOCKET:
113 >                return "socket failed";
114 >        case SG_ERROR_SWAPCTL:
115 >                return "swapctl failed";
116 >        case SG_ERROR_SYSCONF:
117 >                return "sysconf failed";
118 >        case SG_ERROR_SYSCTL:
119 >                return "sysctl failed";
120 >        case SG_ERROR_SYSCTLBYNAME:
121 >                return "sysctlbyname failed";
122 >        case SG_ERROR_SYSCTLNAMETOMIB:
123 >                return "sysctlnametomib failed";
124 >        case SG_ERROR_UNAME:
125 >                return "uname failed";
126 >        case SG_ERROR_UNSUPPORTED:
127 >                return "unsupported function";
128 >        case SG_ERROR_XSW_VER_MISMATCH:
129 >                return "XSW version mismatch";
130 >        }
131 >        return "unknown error";
132   }
133  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines