root/lm-sensors/branches/lm-sensors-3.0.0/lib/error.c @ 4899

Revision 4899, 2.3 KB (checked in by khali, 7 years ago)

libsensors: Report I/O errors as such.

  • 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        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., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#include <stdlib.h>
22#include <stdio.h>
23#include "error.h"
24#include "general.h"
25
26static void sensors_default_parse_error(const char *err, int lineno);
27static void sensors_default_fatal_error(const char *proc, const char *err);
28
29void (*sensors_parse_error) (const char *err, int lineno) =
30                                                sensors_default_parse_error;
31void (*sensors_fatal_error) (const char *proc, const char *err) =
32                                                sensors_default_fatal_error;
33
34static const char *errorlist[] = {
35        /* Invalid error code    */ NULL,
36        /* SENSORS_ERR_WILDCARDS */ "Wildcard found in chip name",
37        /* SENSORS_ERR_NO_ENTRY  */ "No such subfeature known",
38        /* SENSORS_ERR_ACCESS_R  */ "Can't read",
39        /* SENSORS_ERR_KERNEL    */ "Kernel interface error",
40        /* SENSORS_ERR_DIV_ZERO  */ "Divide by zero",
41        /* SENSORS_ERR_CHIP_NAME */ "Can't parse chip name",
42        /* SENSORS_ERR_BUS_NAME  */ "Can't parse bus name",
43        /* SENSORS_ERR_PARSE     */ "General parse error",
44        /* SENSORS_ERR_ACCESS_W  */ "Can't write",
45        /* SENSORS_ERR_IO        */ "I/O error",
46};
47
48const char *sensors_strerror(int errnum)
49{
50        if (errnum < 0)
51                errnum = -errnum;
52        if (errnum >= ARRAY_SIZE(errorlist))
53                errnum = 0;
54        return errorlist[errnum];
55}
56
57void sensors_default_parse_error(const char *err, int lineno)
58{
59        fprintf(stderr, "Error: Line %d: %s\n", lineno, err);
60}
61
62void sensors_default_fatal_error(const char *proc, const char *err)
63{
64        fprintf(stderr, "Fatal error in `%s': %s\n", proc, err);
65        exit(1);
66}
Note: See TracBrowser for help on using the browser.