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

Revision 5633, 2.4 KB (checked in by khali, 6 years ago)

Return a string rather than NULL for unknown errors. Patch from
Andre Prendel.

  • 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, 2008  Jean Delvare <khali@linux-fr.org>
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10
11    This program 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 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_fatal_error(const char *proc, const char *err);
29
30void (*sensors_parse_error) (const char *err, int lineno) =
31                                                sensors_default_parse_error;
32void (*sensors_fatal_error) (const char *proc, const char *err) =
33                                                sensors_default_fatal_error;
34
35static const char *errorlist[] = {
36        /* Invalid error code    */ "Unknown error",
37        /* SENSORS_ERR_WILDCARDS */ "Wildcard found in chip name",
38        /* SENSORS_ERR_NO_ENTRY  */ "No such subfeature known",
39        /* SENSORS_ERR_ACCESS_R  */ "Can't read",
40        /* SENSORS_ERR_KERNEL    */ "Kernel interface error",
41        /* SENSORS_ERR_DIV_ZERO  */ "Divide by zero",
42        /* SENSORS_ERR_CHIP_NAME */ "Can't parse chip name",
43        /* SENSORS_ERR_BUS_NAME  */ "Can't parse bus name",
44        /* SENSORS_ERR_PARSE     */ "General parse error",
45        /* SENSORS_ERR_ACCESS_W  */ "Can't write",
46        /* SENSORS_ERR_IO        */ "I/O error",
47        /* SENSORS_ERR_RECURSION */ "Evaluation recurses too deep",
48};
49
50const char *sensors_strerror(int errnum)
51{
52        if (errnum < 0)
53                errnum = -errnum;
54        if (errnum >= ARRAY_SIZE(errorlist))
55                errnum = 0;
56        return errorlist[errnum];
57}
58
59void sensors_default_parse_error(const char *err, int lineno)
60{
61        fprintf(stderr, "Error: Line %d: %s\n", lineno, err);
62}
63
64void sensors_default_fatal_error(const char *proc, const char *err)
65{
66        fprintf(stderr, "Fatal error in `%s': %s\n", proc, err);
67        exit(1);
68}
Note: See TracBrowser for help on using the browser.