root/lm-sensors/trunk/lib/error.c @ 5844

Revision 5844, 3.2 KB (checked in by khali, 4 years ago)

Change libsensors license from GPL to LGPL.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/*
2    error.c - Part of libsensors, a Linux library for reading sensor data.
3    Copyright (c) 1998, 1999  Frodo Looijaard <frodol@dds.nl>
4    Copyright (C) 2007-2009   Jean Delvare <khali@linux-fr.org>
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
14    GNU Lesser General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19    MA 02110-1301 USA.
20*/
21
22#include <stdlib.h>
23#include <stdio.h>
24#include "error.h"
25#include "general.h"
26
27static void sensors_default_parse_error(const char *err, int lineno);
28static void sensors_default_parse_error_wfn(const char *err,
29                                            const char *filename, int lineno);
30static void sensors_default_fatal_error(const char *proc, const char *err);
31
32void (*sensors_parse_error) (const char *err, int lineno) =
33                                                sensors_default_parse_error;
34void (*sensors_parse_error_wfn) (const char *err, const char *filename,
35                                 int lineno) = sensors_default_parse_error_wfn;
36void (*sensors_fatal_error) (const char *proc, const char *err) =
37                                                sensors_default_fatal_error;
38
39static const char *errorlist[] = {
40        /* Invalid error code    */ "Unknown error",
41        /* SENSORS_ERR_WILDCARDS */ "Wildcard found in chip name",
42        /* SENSORS_ERR_NO_ENTRY  */ "No such subfeature known",
43        /* SENSORS_ERR_ACCESS_R  */ "Can't read",
44        /* SENSORS_ERR_KERNEL    */ "Kernel interface error",
45        /* SENSORS_ERR_DIV_ZERO  */ "Divide by zero",
46        /* SENSORS_ERR_CHIP_NAME */ "Can't parse chip name",
47        /* SENSORS_ERR_BUS_NAME  */ "Can't parse bus name",
48        /* SENSORS_ERR_PARSE     */ "General parse error",
49        /* SENSORS_ERR_ACCESS_W  */ "Can't write",
50        /* SENSORS_ERR_IO        */ "I/O error",
51        /* SENSORS_ERR_RECURSION */ "Evaluation recurses too deep",
52};
53
54const char *sensors_strerror(int errnum)
55{
56        if (errnum < 0)
57                errnum = -errnum;
58        if (errnum >= ARRAY_SIZE(errorlist))
59                errnum = 0;
60        return errorlist[errnum];
61}
62
63void sensors_default_parse_error(const char *err, int lineno)
64{
65        if (lineno)
66                fprintf(stderr, "Error: Line %d: %s\n", lineno, err);
67        else
68                fprintf(stderr, "Error: %s\n", err);
69}
70
71void sensors_default_parse_error_wfn(const char *err,
72                                     const char *filename, int lineno)
73{
74        /* If application provided a custom parse error reporting function
75           but not the variant with the filename, fall back to the original
76           variant without the filename, for backwards compatibility. */
77        if (sensors_parse_error != sensors_default_parse_error ||
78            !filename)
79                return sensors_parse_error(err, lineno);
80
81        if (lineno)
82                fprintf(stderr, "Error: File %s, line %d: %s\n", filename,
83                        lineno, err);
84        else
85                fprintf(stderr, "Error: File %s: %s\n", filename, err);
86}
87
88void sensors_default_fatal_error(const char *proc, const char *err)
89{
90        fprintf(stderr, "Fatal error in `%s': %s\n", proc, err);
91        exit(1);
92}
Note: See TracBrowser for help on using the browser.