ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/libstatgrab/src/libstatgrab/error.c
Revision: 1.11
Committed: Thu Apr 8 11:14:02 2004 UTC (20 years, 1 month ago) by ats
Content type: text/plain
Branch: MAIN
CVS Tags: LIBSTATGRAB_0_10
Changes since 1.10: +2 -1 lines
Log Message:
... and include tools.h to get the definition of sg_strlcpy.

File Contents

# User Rev Content
1 tdb 1.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 ats 1.11 * $Id: error.c,v 1.10 2004/04/08 11:01:44 ats Exp $
22 tdb 1.1 */
23    
24     #ifdef HAVE_CONFIG_H
25     #include "config.h"
26     #endif
27    
28     #include <stdlib.h>
29    
30     #include "statgrab.h"
31 ats 1.11 #include "tools.h"
32 tdb 1.1
33 ats 1.2 static sg_error error = SG_ERROR_NONE;
34 ats 1.8 #define ERROR_ARG_MAX 256
35     static char error_arg[ERROR_ARG_MAX];
36 tdb 1.1
37     void sg_set_error(sg_error code, const char *arg) {
38     error = code;
39 tdb 1.9 if (arg != NULL) {
40 ats 1.10 sg_strlcpy(error_arg, arg, sizeof error_arg);
41 tdb 1.9 }
42     else {
43     /* FIXME is this the best idea? */
44     error_arg[0] = '\0';
45     }
46 tdb 1.1 }
47    
48     sg_error sg_get_error() {
49     return error;
50     }
51    
52 ats 1.8 const char *sg_get_error_arg() {
53     return error_arg;
54     }
55    
56 ats 1.2 const char *sg_str_error(sg_error code) {
57     switch (code) {
58     case SG_ERROR_NONE:
59     return "no error";
60 tdb 1.7 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 tdb 1.4 case SG_ERROR_MALLOC:
87     return "malloc failed";
88     case SG_ERROR_OPEN:
89     return "failed to open file";
90 tdb 1.7 case SG_ERROR_OPENDIR:
91     return "failed to open directory";
92 tdb 1.4 case SG_ERROR_PARSE:
93     return "failed to parse input";
94 tdb 1.7 case SG_ERROR_SETEGID:
95     return "setegid failed";
96     case SG_ERROR_SETEUID:
97     return "seteuid failed";
98 tdb 1.6 case SG_ERROR_SETMNTENT:
99     return "setmntent failed";
100 tdb 1.7 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 ats 1.2 }
119 ats 1.8 return "unknown error";
120 tdb 1.1 }
121