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.11 by ats, Thu Apr 8 11:14:02 2004 UTC

# Line 28 | Line 28
28   #include <stdlib.h>
29  
30   #include "statgrab.h"
31 + #include "tools.h"
32  
33 < static sg_error error;
33 > static sg_error error = SG_ERROR_NONE;
34 > #define ERROR_ARG_MAX 256
35 > static char error_arg[ERROR_ARG_MAX];
36  
37   void sg_set_error(sg_error code, const char *arg) {
38          error = code;
39 +        if (arg != NULL) {
40 +                sg_strlcpy(error_arg, arg, sizeof error_arg);
41 +        }
42 +        else {
43 +                /* FIXME is this the best idea? */
44 +                error_arg[0] = '\0';
45 +        }
46   }
47  
48   sg_error sg_get_error() {
49          return error;
50   }
51  
52 < char *sg_str_error(sg_error code) {
53 <        return NULL;
52 > const char *sg_get_error_arg() {
53 >        return error_arg;
54 > }
55 >
56 > const char *sg_str_error(sg_error code) {
57 >        switch (code) {
58 >        case SG_ERROR_NONE:
59 >                return "no error";
60 >        case SG_ERROR_ASPRINTF:
61 >                return "asprintf failed";
62 >        case SG_ERROR_DEVSTAT_GETDEVS:
63 >                return "devstat_getdevs failed";
64 >        case SG_ERROR_DEVSTAT_SELECTDEVS:
65 >                return "devstat_selectdevs failed";
66 >        case SG_ERROR_ENOENT:
67 >                return "system call received ENOENT";
68 >        case SG_ERROR_GETIFADDRS:
69 >                return "getifaddress failed";
70 >        case SG_ERROR_GETMNTINFO:
71 >                return "getmntinfo failed";
72 >        case SG_ERROR_GETPAGESIZE:
73 >                return "getpagesize failed";
74 >        case SG_ERROR_KSTAT_DATA_LOOKUP:
75 >                return "kstat_data_lookup failed";
76 >        case SG_ERROR_KSTAT_LOOKUP:
77 >                return "kstat_lookup failed";
78 >        case SG_ERROR_KSTAT_OPEN:
79 >                return "kstat_open failed";
80 >        case SG_ERROR_KSTAT_READ:
81 >                return "kstat_read failed";
82 >        case SG_ERROR_KVM_GETSWAPINFO:
83 >                return "kvm_getswapinfo failed";
84 >        case SG_ERROR_KVM_OPENFILES:
85 >                return "kvm_openfiles failed";
86 >        case SG_ERROR_MALLOC:
87 >                return "malloc failed";
88 >        case SG_ERROR_OPEN:
89 >                return "failed to open file";
90 >        case SG_ERROR_OPENDIR:
91 >                return "failed to open directory";
92 >        case SG_ERROR_PARSE:
93 >                return "failed to parse input";
94 >        case SG_ERROR_SETEGID:
95 >                return "setegid failed";
96 >        case SG_ERROR_SETEUID:
97 >                return "seteuid failed";
98 >        case SG_ERROR_SETMNTENT:
99 >                return "setmntent failed";
100 >        case SG_ERROR_SOCKET:
101 >                return "socket failed";
102 >        case SG_ERROR_SWAPCTL:
103 >                return "swapctl failed";
104 >        case SG_ERROR_SYSCONF:
105 >                return "sysconf failed";
106 >        case SG_ERROR_SYSCTL:
107 >                return "sysctl failed";
108 >        case SG_ERROR_SYSCTLBYNAME:
109 >                return "sysctlbyname failed";
110 >        case SG_ERROR_SYSCTLNAMETOMIB:
111 >                return "sysctlnametomib failed";
112 >        case SG_ERROR_UNAME:
113 >                return "uname failed";
114 >        case SG_ERROR_UNSUPPORTED:
115 >                return "unsupported function";
116 >        case SG_ERROR_XSW_VER_MISMATCH:
117 >                return "XSW version mismatch";
118 >        }
119 >        return "unknown error";
120   }
121  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines