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

Revision 120, 2.2 KB (checked in by frodo, 14 years ago)

Some library cleanup; no interface changes

  • 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  Frodo Looijaard <frodol@dds.nl>
4
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2 of the License, or
8    (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18*/
19
20#include <stdio.h>
21#include "error.h"
22
23static void sensors_default_parse_error(const char *err, int lineno);
24static void sensors_default_fatal_error(const char *proc,const char *err);
25
26void (*sensors_parse_error) (const char *err, int lineno) = 
27                                                  sensors_default_parse_error;
28void (*sensors_fatal_error) (const char *proc, const char *err) = 
29                                                  sensors_default_fatal_error;
30
31static const char *errorlist[] =
32 { /* Unknown error         */ "sensors_strerror: Unknown error!",
33   /* SENSORS_ERR_WILDCARDS */ "Wildcard found in chip name",
34   /* SENSORS_ERR_NO_ENTRY  */ "No such feature known",
35   /* SENSORS_ERR_ACCESS    */ "Can't read or write",
36   /* SENSORS_ERR_PROC      */ "Can't access /proc file",
37   /* SENSORS_ERR_DIV_ZERO  */ "Divide by zero",
38   /* SENSORS_ERR_CHIP_NAME */ "Can't parse chip name",
39   /* SENSORS_ERR_BUS_NAME  */ "Can't parse bus name"
40 };
41
42#define ERROR_LIST_LEN (sizeof(errorlist) / sizeof(char *))
43
44const char *sensors_strerror(int errnum)
45{
46  if (errnum < 0)
47    errnum = -errnum;
48  if (errnum >= ERROR_LIST_LEN)
49    errnum = 0;
50  return errorlist[errnum];
51} 
52
53void sensors_default_parse_error(const char *err, int lineno)
54{
55  fprintf(stderr,"Error: Line %d: %s\n",lineno,err);
56}
57
58void sensors_default_fatal_error(const char *proc, const char *err)
59{
60  fprintf(stderr,"Fatal error in `%s': %s\n",proc,err);
61  exit(1);
62}
Note: See TracBrowser for help on using the browser.