remove suidregister
[comedilib.git] / lib / get.c
1 /*
2     lib/get.c
3     comedi library routines
4
5     COMEDI - Linux Control and Measurement Device Interface
6     Copyright (C) 1997-8 David A. Schleef <ds@stm.lbl.gov>
7
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.
12
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.
17
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.
21
22 */
23
24 #include <stdio.h>
25 #include <math.h>
26 #include <stdlib.h>
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #include <fcntl.h>
30 #include <unistd.h>
31 #include <sys/ioctl.h>
32 #include <errno.h>
33 #include <comedi.h>
34 #include <string.h>
35
36 #include <libinternal.h>
37
38
39 int comedi_get_n_subdevices(comedi_t *it)
40 {
41         if(!valid_dev(it))
42                 return -1;
43
44         return it->n_subdevices;
45 }
46
47 int comedi_get_version_code(comedi_t *it)
48 {
49         if(!valid_dev(it))
50                 return -1;
51
52         return it->devinfo.version_code;
53 }
54
55 char *comedi_get_driver_name(comedi_t *it)
56 {
57         if(!valid_dev(it))
58                 return NULL;
59
60         return it->devinfo.driver_name;
61 }
62
63 char *comedi_get_board_name(comedi_t *it)
64 {
65         if(!valid_dev(it))
66                 return NULL;
67
68         return it->devinfo.board_name;
69 }
70
71 int comedi_get_subdevice_flags(comedi_t *it,unsigned int subd)
72 {
73         if(!valid_dev(it))
74                 return 0;
75
76         return it->subdevices[subd].subd_flags;
77 }
78
79 int comedi_get_subdevice_type(comedi_t *it,unsigned int subd)
80 {
81         if(!valid_dev(it))
82                 return -1;
83
84         return it->subdevices[subd].type;
85 }
86
87 int comedi_find_subdevice_by_type(comedi_t *it,int type,unsigned int subd)
88 {
89         if(!valid_subd(it,subd))
90                 return -1;
91
92         for(;subd<it->n_subdevices;subd++){
93                 if(it->subdevices[subd].type==type)
94                         return subd;
95         }
96         return -1;
97 }
98
99
100 int comedi_get_n_channels(comedi_t *it,unsigned int subd)
101 {
102         if(!valid_subd(it,subd))
103                 return -1;
104
105         return it->subdevices[subd].n_chan;
106 }
107
108
109 /* */
110
111 lsampl_t comedi_get_maxdata(comedi_t *it,unsigned int subdevice,unsigned int chan)
112 {
113         if(!valid_chan(it,subdevice,chan))
114                 return 0;
115
116         if(it->subdevices[subdevice].maxdata_list)
117                 return it->subdevices[subdevice].maxdata_list[chan];
118
119         return it->subdevices[subdevice].maxdata;
120 }
121
122 int comedi_maxdata_is_chan_specific(comedi_t *it,unsigned int subdevice)
123 {
124         if(it->subdevices[subdevice].maxdata_list)
125                 return 1;
126         return 0;
127 }
128
129 int comedi_get_rangetype(comedi_t *it,unsigned int subdevice,unsigned int chan)
130 {
131         if(!valid_chan(it,subdevice,chan))
132                 return -1;
133
134         if(it->subdevices[subdevice].range_type_list)
135                 return it->subdevices[subdevice].range_type_list[chan];
136
137         return it->subdevices[subdevice].range_type;
138 }
139
140
141 comedi_range * comedi_get_range(comedi_t *it,unsigned int subdevice,unsigned int chan,unsigned int range)
142 {
143         int range_type;
144
145         if(!valid_chan(it,subdevice,chan))
146                 return NULL;
147
148         range_type=comedi_get_rangetype(it,subdevice,chan);
149
150         if(range>=RANGE_LENGTH(range_type))
151                 return NULL;
152
153         if(it->subdevices[subdevice].rangeinfo_list)
154                 return it->subdevices[subdevice].rangeinfo_list[chan]+range;
155
156         return it->subdevices[subdevice].rangeinfo+range;
157 }
158
159