3 error functions and data
5 COMEDILIB - Linux Control and Measurement Device Interface Library
6 Copyright (C) 1997-2001 David A. Schleef <ds@schleef.org>
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation, version 2.1
13 This library 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 GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 #include "libinternal.h"
29 char *__comedilib_error_strings[]={
32 _s("Bad comedi_t structure"),
33 _s("Invalid subdevice"),
34 _s("Invalid channel"),
35 _s("Buffer overflow"),
36 _s("Buffer underflow"),
37 _s("Command not supported"),
40 #define n_errors (sizeof(__comedilib_error_strings)/sizeof(void *))
42 int __comedi_loglevel=1;
45 EXPORT_SYMBOL(comedi_loglevel,0.7.18);
46 int comedi_loglevel(int loglevel)
48 int old_loglevel=__comedi_loglevel;
50 __comedi_loglevel=loglevel;
55 EXPORT_SYMBOL(comedi_errno,0.7.18);
56 int comedi_errno(void)
58 return __comedi_errno;
61 EXPORT_SYMBOL(comedi_strerror,0.7.18);
62 char *comedi_strerror(int errnum)
64 if(errnum<COMEDI_NOERROR || errnum>=COMEDI_NOERROR+n_errors)
65 return strerror(errnum);
67 return GETTEXT(__comedilib_error_strings[errnum-COMEDI_NOERROR]);
70 EXPORT_SYMBOL(comedi_perror,0.7.18);
71 void comedi_perror(const char *s)
73 if(__comedi_loglevel>=3){
74 fprintf(stderr,"comedi_perror(): __comedi_errno=%d\n",__comedi_errno);
77 fprintf(stderr,"%s: %s\n",s,comedi_strerror(__comedi_errno));
83 if(__comedi_loglevel>=2){
84 comedi_perror("libc error");
88 void internal_error(int err)
91 if(__comedi_loglevel>=2){
92 comedi_perror("internal error");
98 int valid_dev(comedi_t *it)
100 if(!it || it->magic!=COMEDILIB_MAGIC){
101 internal_error(COMEDILIB_BADDEV);
108 int valid_subd(comedi_t *it,unsigned int subd)
110 if(!valid_dev(it))return 0;
111 if(subd>=it->n_subdevices){
112 internal_error(COMEDILIB_BADSUBD);
119 int valid_chan(comedi_t *it,unsigned int subd,unsigned int chan)
121 if(!valid_subd(it,subd))return 0;
122 if(chan>=it->subdevices[subd].n_chan){
123 internal_error(COMEDILIB_BADCHAN);