3 error handling routines
5 COMEDI - Linux Control and Measurement Device Interface
6 Copyright (C) 1997-8 David A. Schleef <ds@stm.lbl.gov>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <libinternal.h>
28 #include <comedi_errno.h>
30 char *__comedilib_error_strings[]={
33 "Bad comedi_t structure",
38 "Command not supported",
41 #define n_errors (sizeof(__comedilib_error_strings)/sizeof(void *))
43 int __comedi_loglevel=1;
46 int comedi_loglevel(int loglevel)
48 int old_loglevel=__comedi_loglevel;
50 __comedi_loglevel=loglevel;
55 int comedi_errno(void)
57 return __comedi_errno;
60 char *comedi_strerror(int errnum)
62 if(errnum<COMEDI_NOERROR || errnum>=COMEDI_NOERROR+n_errors)
63 return strerror(errnum);
65 return __comedilib_error_strings[errnum-COMEDI_NOERROR];
68 void comedi_perror(const char *s)
70 if(__comedi_loglevel>=3){
71 fprintf(stderr,"comedi_perror(): __comedi_errno=%d\n",__comedi_errno);
74 fprintf(stderr,"%s: %s\n",s,comedi_strerror(__comedi_errno));
80 if(__comedi_loglevel>=2){
81 comedi_perror("libc error");
85 void internal_error(int err)
88 if(__comedi_loglevel>=2){
89 comedi_perror("internal error");
95 int valid_dev(comedi_t *it)
97 if(!it || it->magic!=COMEDILIB_MAGIC){
98 internal_error(COMEDILIB_BADDEV);
105 int valid_subd(comedi_t *it,unsigned int subd)
107 if(!valid_dev(it))return 0;
108 if(subd>=it->n_subdevices){
109 internal_error(COMEDILIB_BADSUBD);
116 int valid_chan(comedi_t *it,unsigned int subd,unsigned int chan)
118 if(!valid_subd(it,subd))return 0;
119 if(chan>=it->subdevices[subd].n_chan){
120 internal_error(COMEDILIB_BADCHAN);