ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/libstatgrab/src/libstatgrab/error.c
Revision: 1.16
Committed: Mon Nov 1 18:30:17 2004 UTC (19 years, 6 months ago) by tdb
Content type: text/plain
Branch: MAIN
CVS Tags: LIBSTATGRAB_0_12, LIBSTATGRAB_0_11_1, LIBSTATGRAB_0_11
Changes since 1.15: +3 -1 lines
Log Message:
Merge in patch to provide support for HP-UX 11.11.

Contributed by Roy Keene - thanks Roy!

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 tdb 1.16 * $Id: error.c,v 1.15 2004/07/18 20:44:01 ats Exp $
22 tdb 1.1 */
23    
24     #ifdef HAVE_CONFIG_H
25     #include "config.h"
26     #endif
27    
28     #include <stdlib.h>
29 tdb 1.12 #include <string.h>
30     #include <errno.h>
31 tdb 1.1
32     #include "statgrab.h"
33 ats 1.11 #include "tools.h"
34 tdb 1.1
35 ats 1.2 static sg_error error = SG_ERROR_NONE;
36 ats 1.8 #define ERROR_ARG_MAX 256
37     static char error_arg[ERROR_ARG_MAX];
38 tdb 1.13 static int errno_value = 0;
39 tdb 1.1
40     void sg_set_error(sg_error code, const char *arg) {
41 ats 1.14 errno_value = 0;
42 tdb 1.1 error = code;
43 tdb 1.9 if (arg != NULL) {
44 ats 1.10 sg_strlcpy(error_arg, arg, sizeof error_arg);
45 tdb 1.9 }
46     else {
47     /* FIXME is this the best idea? */
48     error_arg[0] = '\0';
49     }
50 tdb 1.1 }
51    
52 tdb 1.13 void sg_set_error_with_errno(sg_error code, const char *arg) {
53 ats 1.14 sg_set_error(code, arg);
54 tdb 1.13 errno_value = errno;
55 tdb 1.12 }
56    
57 tdb 1.1 sg_error sg_get_error() {
58     return error;
59     }
60    
61 ats 1.8 const char *sg_get_error_arg() {
62     return error_arg;
63 tdb 1.12 }
64    
65 ats 1.15 int sg_get_error_errno() {
66 tdb 1.13 return errno_value;
67 ats 1.8 }
68    
69 ats 1.2 const char *sg_str_error(sg_error code) {
70     switch (code) {
71     case SG_ERROR_NONE:
72     return "no error";
73 tdb 1.7 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_KSTAT_DATA_LOOKUP:
88     return "kstat_data_lookup failed";
89     case SG_ERROR_KSTAT_LOOKUP:
90     return "kstat_lookup failed";
91     case SG_ERROR_KSTAT_OPEN:
92     return "kstat_open failed";
93     case SG_ERROR_KSTAT_READ:
94     return "kstat_read failed";
95     case SG_ERROR_KVM_GETSWAPINFO:
96     return "kvm_getswapinfo failed";
97     case SG_ERROR_KVM_OPENFILES:
98     return "kvm_openfiles failed";
99 tdb 1.4 case SG_ERROR_MALLOC:
100     return "malloc failed";
101     case SG_ERROR_OPEN:
102     return "failed to open file";
103 tdb 1.7 case SG_ERROR_OPENDIR:
104     return "failed to open directory";
105 tdb 1.4 case SG_ERROR_PARSE:
106     return "failed to parse input";
107 tdb 1.7 case SG_ERROR_SETEGID:
108     return "setegid failed";
109     case SG_ERROR_SETEUID:
110     return "seteuid failed";
111 tdb 1.6 case SG_ERROR_SETMNTENT:
112     return "setmntent failed";
113 tdb 1.7 case SG_ERROR_SOCKET:
114     return "socket failed";
115     case SG_ERROR_SWAPCTL:
116     return "swapctl failed";
117     case SG_ERROR_SYSCONF:
118     return "sysconf failed";
119     case SG_ERROR_SYSCTL:
120     return "sysctl failed";
121     case SG_ERROR_SYSCTLBYNAME:
122     return "sysctlbyname failed";
123     case SG_ERROR_SYSCTLNAMETOMIB:
124     return "sysctlnametomib failed";
125     case SG_ERROR_UNAME:
126     return "uname failed";
127     case SG_ERROR_UNSUPPORTED:
128     return "unsupported function";
129     case SG_ERROR_XSW_VER_MISMATCH:
130     return "XSW version mismatch";
131 tdb 1.16 case SG_ERROR_PSTAT:
132     return "pstat failed";
133 ats 1.2 }
134 ats 1.8 return "unknown error";
135 tdb 1.1 }
136