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>
30 char *__comedilib_error_strings[]={
33 "Bad comedi_t structure",
38 int __comedi_loglevel=1;
41 int comedi_loglevel(int loglevel)
43 int old_loglevel=__comedi_loglevel;
45 __comedi_loglevel=loglevel;
50 int comedi_errno(void)
52 return __comedi_errno;
55 char *comedi_strerror(int errnum)
57 if(errnum<COMEDILIB_NOERROR ||
58 errnum>=COMEDILIB_NOERROR+sizeof(__comedilib_error_strings)
59 /sizeof(__comedilib_error_strings[0]))
60 return strerror(errnum);
62 return __comedilib_error_strings[errnum-COMEDILIB_NOERROR];
65 void comedi_perror(const char *s)
67 if(__comedi_loglevel>=3){
68 fprintf(stderr,"comedi_perror(): __comedi_errno=%d\n",__comedi_errno);
71 fprintf(stderr,"%s: %s\n",s,comedi_strerror(__comedi_errno));
77 if(__comedi_loglevel>=2){
78 comedi_perror("libc error");
82 void internal_error(int err)
85 if(__comedi_loglevel>=2){
86 comedi_perror("internal error");
92 int valid_dev(comedi_t *it)
94 if(!it || it->magic!=COMEDILIB_MAGIC){
95 internal_error(COMEDILIB_BADDEV);
102 int valid_subd(comedi_t *it,unsigned int subd)
104 if(!valid_dev(it))return 0;
105 if(subd>=it->n_subdevices){
106 internal_error(COMEDILIB_BADSUBD);
113 int valid_chan(comedi_t *it,unsigned int subd,unsigned int chan)
115 if(!valid_subd(it,subd))return 0;
116 if(chan>=it->subdevices[subd].n_chan){
117 internal_error(COMEDILIB_BADCHAN);