![]() |
RTXI 1.3
|
00001 /* 00002 lib/error.c 00003 error functions and data 00004 00005 COMEDILIB - Linux Control and Measurement Device Interface Library 00006 Copyright (C) 1997-2001 David A. Schleef <ds@schleef.org> 00007 00008 This library is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU Lesser General Public 00010 License as published by the Free Software Foundation, version 2.1 00011 of the License. 00012 00013 This library is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 Lesser General Public License for more details. 00017 00018 You should have received a copy of the GNU Lesser General Public 00019 License along with this library; if not, write to the Free Software 00020 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00021 USA. 00022 */ 00023 00024 #include "libinternal.h" 00025 00026 #include <stdio.h> 00027 #include <string.h> 00028 00029 char *__comedilib_error_strings[]={ 00030 _s("No error"), 00031 _s("Unknown error"), 00032 _s("Bad comedi_t structure"), 00033 _s("Invalid subdevice"), 00034 _s("Invalid channel"), 00035 _s("Buffer overflow"), 00036 _s("Buffer underflow"), 00037 _s("Command not supported"), 00038 _s("Not supported"), 00039 }; 00040 #define n_errors (sizeof(__comedilib_error_strings)/sizeof(void *)) 00041 00042 int __comedi_loglevel=1; 00043 TLS int __comedi_errno=0; 00044 00045 EXPORT_ALIAS_DEFAULT(_comedi_loglevel,comedi_loglevel,0.7.18); 00046 int _comedi_loglevel(int loglevel) 00047 { 00048 int old_loglevel=__comedi_loglevel; 00049 00050 __comedi_loglevel=loglevel; 00051 00052 return old_loglevel; 00053 } 00054 00055 EXPORT_ALIAS_DEFAULT(_comedi_errno,comedi_errno,0.7.18); 00056 int _comedi_errno(void) 00057 { 00058 return __comedi_errno; 00059 } 00060 00061 EXPORT_ALIAS_DEFAULT(_comedi_strerror,comedi_strerror,0.7.18); 00062 const char* _comedi_strerror(int errnum) 00063 { 00064 if(errnum<COMEDI_NOERROR || errnum>=COMEDI_NOERROR+n_errors) 00065 return strerror(errnum); 00066 00067 return GETTEXT(__comedilib_error_strings[errnum-COMEDI_NOERROR]); 00068 } 00069 00070 EXPORT_ALIAS_DEFAULT(_comedi_perror,comedi_perror,0.7.18); 00071 void _comedi_perror(const char *s) 00072 { 00073 if(__comedi_loglevel>=3){ 00074 fprintf(stderr,"comedi_perror(): __comedi_errno=%d\n",__comedi_errno); 00075 } 00076 if(!s)s="comedilib"; 00077 fprintf(stderr,"%s: %s\n",s,comedi_strerror(__comedi_errno)); 00078 } 00079 00080 void libc_error(void) 00081 { 00082 __comedi_errno=errno; 00083 if(__comedi_loglevel>=2){ 00084 comedi_perror("libc error"); 00085 } 00086 } 00087 00088 void internal_error(int err) 00089 { 00090 __comedi_errno=err; 00091 if(__comedi_loglevel>=2){ 00092 comedi_perror("internal error"); 00093 } 00094 } 00095 00096 00097 00098 int valid_dev(comedi_t *it) 00099 { 00100 if(!it || it->magic!=COMEDILIB_MAGIC){ 00101 internal_error(EBAD_CT); 00102 return 0; 00103 } 00104 00105 return 1; 00106 } 00107 00108 int valid_subd(comedi_t *it,unsigned int subd) 00109 { 00110 if(!valid_dev(it))return 0; 00111 if(subd>=it->n_subdevices){ 00112 internal_error(EINVAL_SUBD); 00113 return 0; 00114 } 00115 00116 return 1; 00117 } 00118 00119 int valid_chan(comedi_t *it,unsigned int subd,unsigned int chan) 00120 { 00121 if(!valid_subd(it,subd))return 0; 00122 if(chan>=it->subdevices[subd].n_chan){ 00123 internal_error(EINVAL_CHAN); 00124 return 0; 00125 } 00126 00127 return 1; 00128 } 00129 00130