66 * Author: Paul Cercueil <[email protected] > 77 */
88
9- #include "iio-private.h"
10- #include "sort.h"
11-
12- #include <inttypes.h>
139#include <errno.h>
10+ #include <inttypes.h>
1411#include <stdio.h>
1512#include <string.h>
1613
17- static inline unsigned int attr_index (const struct iio_attr_list * list ,
18- const struct iio_attr * attr )
14+ #include "iio-private.h"
15+ #include "sort.h"
16+
17+ static inline unsigned int attr_index (
18+ const struct iio_attr_list * list , const struct iio_attr * attr )
1919{
2020 uintptr_t diff = (uintptr_t )attr - (uintptr_t )list -> attrs ;
2121 return (unsigned int )diff / sizeof (* attr );
@@ -28,7 +28,8 @@ ssize_t iio_attr_read_raw(const struct iio_attr *attr, char *dst, size_t len)
2828
2929 if (attr -> type == IIO_ATTR_TYPE_CONTEXT ) {
3030 idx = attr_index (& attr -> iio .ctx -> attrlist , attr );
31- return (ssize_t ) iio_strlcpy (dst , attr -> iio .ctx -> values [idx ], len );
31+ return (ssize_t )iio_strlcpy (
32+ dst , attr -> iio .ctx -> values [idx ], len );
3233 }
3334
3435 if (dev -> ctx -> ops -> read_attr )
@@ -45,7 +46,7 @@ int iio_attr_read_longlong(const struct iio_attr *attr, long long *val)
4546
4647 ret = iio_attr_read_raw (attr , buf , sizeof (buf ));
4748 if (ret < 0 )
48- return (int ) ret ;
49+ return (int )ret ;
4950
5051 errno = 0 ;
5152 value = strtoll (buf , & end , 0 );
@@ -75,13 +76,13 @@ int iio_attr_read_double(const struct iio_attr *attr, double *val)
7576
7677 ret = iio_attr_read_raw (attr , buf , sizeof (buf ));
7778 if (ret < 0 )
78- return (int ) ret ;
79+ return (int )ret ;
7980
8081 return read_double (buf , val );
8182}
8283
83- ssize_t iio_attr_write_raw (const struct iio_attr * attr ,
84- const void * src , size_t len )
84+ ssize_t iio_attr_write_raw (
85+ const struct iio_attr * attr , const void * src , size_t len )
8586{
8687 const struct iio_device * dev = iio_attr_get_device (attr );
8788
@@ -96,7 +97,8 @@ ssize_t iio_attr_write_raw(const struct iio_attr *attr,
9697
9798ssize_t iio_attr_write_string (const struct iio_attr * attr , const char * src )
9899{
99- return iio_attr_write_raw (attr , src , strlen (src ) + 1 ); /* Flawfinder: ignore */
100+ return iio_attr_write_raw (
101+ attr , src , strlen (src ) + 1 ); /* Flawfinder: ignore */
100102}
101103
102104int iio_attr_write_longlong (const struct iio_attr * attr , long long val )
@@ -108,18 +110,18 @@ int iio_attr_write_longlong(const struct iio_attr *attr, long long val)
108110 len = iio_snprintf (buf , sizeof (buf ), "%lld" , val );
109111 ret = iio_attr_write_raw (attr , buf , len + 1 );
110112
111- return (int ) (ret < 0 ? ret : 0 );
113+ return (int )(ret < 0 ? ret : 0 );
112114}
113115
114116int iio_attr_write_double (const struct iio_attr * attr , double val )
115117{
116118 ssize_t ret ;
117119 char buf [1024 ];
118120
119- ret = (ssize_t ) write_double (buf , sizeof (buf ), val );
121+ ret = (ssize_t )write_double (buf , sizeof (buf ), val );
120122 if (!ret )
121123 ret = iio_attr_write_string (attr , buf );
122- return (int ) (ret < 0 ? ret : 0 );
124+ return (int )(ret < 0 ? ret : 0 );
123125}
124126
125127int iio_attr_write_bool (const struct iio_attr * attr , bool val )
@@ -131,20 +133,20 @@ int iio_attr_write_bool(const struct iio_attr *attr, bool val)
131133 else
132134 ret = iio_attr_write_raw (attr , "0" , 2 );
133135
134- return (int ) (ret < 0 ? ret : 0 );
136+ return (int )(ret < 0 ? ret : 0 );
135137}
136138
137- const struct iio_attr *
138- iio_attr_get ( const struct iio_attr_list * attrs , unsigned int idx )
139+ const struct iio_attr * iio_attr_get (
140+ const struct iio_attr_list * attrs , unsigned int idx )
139141{
140142 if (idx >= attrs -> num )
141143 return NULL ;
142144
143145 return & attrs -> attrs [idx ];
144146}
145147
146- const struct iio_attr *
147- iio_attr_find ( const struct iio_attr_list * attrs , const char * name )
148+ const struct iio_attr * iio_attr_find (
149+ const struct iio_attr_list * attrs , const char * name )
148150{
149151 unsigned int i ;
150152
@@ -155,20 +157,17 @@ iio_attr_find(const struct iio_attr_list *attrs, const char *name)
155157 return NULL ;
156158}
157159
158- const char *
159- iio_attr_get_name (const struct iio_attr * attr )
160+ const char * iio_attr_get_name (const struct iio_attr * attr )
160161{
161162 return attr -> name ;
162163}
163164
164- const char *
165- iio_attr_get_filename (const struct iio_attr * attr )
165+ const char * iio_attr_get_filename (const struct iio_attr * attr )
166166{
167167 return attr -> filename ;
168168}
169169
170- const char *
171- iio_attr_get_static_value (const struct iio_attr * attr )
170+ const char * iio_attr_get_static_value (const struct iio_attr * attr )
172171{
173172 unsigned int idx ;
174173
@@ -182,8 +181,7 @@ iio_attr_get_static_value(const struct iio_attr *attr)
182181}
183182
184183int iio_add_attr (union iio_pointer p , struct iio_attr_list * attrs ,
185- const char * name , const char * filename ,
186- enum iio_attr_type type )
184+ const char * name , const char * filename , enum iio_attr_type type )
187185{
188186 struct iio_attr * attr ;
189187
@@ -206,7 +204,7 @@ int iio_add_attr(union iio_pointer p, struct iio_attr_list *attrs,
206204 attr [attrs -> num ].filename = iio_strdup (filename );
207205
208206 if (!attr [attrs -> num ].filename ) {
209- free ((char * ) attr [attrs -> num ].name );
207+ free ((char * )attr [attrs -> num ].name );
210208 return - ENOMEM ;
211209 }
212210 } else {
@@ -220,16 +218,18 @@ int iio_add_attr(union iio_pointer p, struct iio_attr_list *attrs,
220218 return 0 ;
221219}
222220
223- static const char * const attr_type_string [] = {
221+ static const char * const attr_type_string [] = {
224222 "" ,
225223 " debug" ,
226224 " buffer" ,
227225};
228226
229- int iio_device_add_attr (struct iio_device * dev ,
230- const char * name , enum iio_attr_type type )
227+ int iio_device_add_attr (struct iio_device * dev , const char * name ,
228+ enum iio_attr_type type )
231229{
232- union iio_pointer p = { .dev = dev , };
230+ union iio_pointer p = {
231+ .dev = dev ,
232+ };
233233 int ret ;
234234
235235 ret = iio_add_attr (p , & dev -> attrlist [type ], name , NULL , type );
@@ -240,26 +240,30 @@ int iio_device_add_attr(struct iio_device *dev,
240240 return 0 ;
241241}
242242
243- int iio_channel_add_attr (struct iio_channel * chn ,
244- const char * name , const char * filename )
243+ int iio_channel_add_attr (
244+ struct iio_channel * chn , const char * name , const char * filename )
245245{
246- union iio_pointer p = { .chn = chn , };
246+ union iio_pointer p = {
247+ .chn = chn ,
248+ };
247249 int ret ;
248250
249251 ret = iio_add_attr (p , & chn -> attrlist , name , filename ,
250- IIO_ATTR_TYPE_CHANNEL );
252+ IIO_ATTR_TYPE_CHANNEL );
251253 if (ret < 0 )
252254 return ret ;
253255
254256 chn_dbg (chn , "Added attr \'%s\' (\'%s\')\n" , name , filename );
255257 return 0 ;
256258}
257259
258- int iio_context_add_attr (struct iio_context * ctx ,
259- const char * key , const char * value )
260+ int iio_context_add_attr (
261+ struct iio_context * ctx , const char * key , const char * value )
260262{
261263 char * * values , * new_val ;
262- union iio_pointer p = { .ctx = ctx , };
264+ union iio_pointer p = {
265+ .ctx = ctx ,
266+ };
263267 unsigned int i ;
264268 int ret ;
265269
@@ -268,7 +272,7 @@ int iio_context_add_attr(struct iio_context *ctx,
268272 return - ENOMEM ;
269273
270274 for (i = 0 ; i < ctx -> attrlist .num ; i ++ ) {
271- if (!strcmp (ctx -> attrlist .attrs [i ].name , key )) {
275+ if (!strcmp (ctx -> attrlist .attrs [i ].name , key )) {
272276 free (ctx -> values [i ]);
273277 ctx -> values [i ] = new_val ;
274278 return 0 ;
@@ -306,7 +310,8 @@ int iio_context_add_attr(struct iio_context *ctx,
306310 causing subsequent attributes to shift forward as they were already sorted */
307311 if (new_idx != ctx -> attrlist .num - 1 ) {
308312 memmove (& ctx -> values [new_idx + 1 ], & ctx -> values [new_idx ],
309- (ctx -> attrlist .num - new_idx - 1 ) * sizeof (* ctx -> values ));
313+ (ctx -> attrlist .num - new_idx - 1 ) *
314+ sizeof (* ctx -> values ));
310315 ctx -> values [new_idx ] = new_val ;
311316 }
312317
@@ -316,9 +321,9 @@ int iio_context_add_attr(struct iio_context *ctx,
316321void iio_free_attr_data (struct iio_attr * attr )
317322{
318323 if (attr -> filename != attr -> name )
319- free ((char * ) attr -> filename );
324+ free ((char * )attr -> filename );
320325
321- free ((char * ) attr -> name );
326+ free ((char * )attr -> name );
322327
323328 attr -> filename = NULL ;
324329 attr -> name = NULL ;
@@ -334,7 +339,8 @@ void iio_free_attrs(const struct iio_attr_list *attrs)
334339 free (attrs -> attrs );
335340}
336341
337- int iio_attr_get_range (const struct iio_attr * attr , double * min , double * step , double * max )
342+ int iio_attr_get_range (const struct iio_attr * attr , double * min , double * step ,
343+ double * max )
338344{
339345 double lmin , lstep , lmax ;
340346 char extra ;
@@ -350,11 +356,12 @@ int iio_attr_get_range(const struct iio_attr *attr, double *min, double *step, d
350356 char buf [MAX_ATTR_VALUE ];
351357 ret = iio_attr_read_raw (attr , buf , sizeof (buf ));
352358 if (ret < 0 )
353- return (int ) ret ;
359+ return (int )ret ;
354360
355- // Expect format: [min step max]
361+ // Expect format: [min step max]
356362#if defined(_MSC_VER )
357- n = iio_sscanf (buf , " [ %lf %lf %lf %c" , & lmin , & lstep , & lmax , & extra , (unsigned int )sizeof (extra ));
363+ n = iio_sscanf (buf , " [ %lf %lf %lf %c" , & lmin , & lstep , & lmax , & extra ,
364+ (unsigned int )sizeof (extra ));
358365#else
359366 n = iio_sscanf (buf , " [ %lf %lf %lf %c" , & lmin , & lstep , & lmax , & extra );
360367#endif
@@ -370,7 +377,8 @@ int iio_attr_get_range(const struct iio_attr *attr, double *min, double *step, d
370377 return 0 ;
371378}
372379
373- int iio_attr_get_available (const struct iio_attr * attr , char * * * list , size_t * count )
380+ int iio_attr_get_available (
381+ const struct iio_attr * attr , char * * * list , size_t * count )
374382{
375383 size_t n = 0 ;
376384 size_t capacity = 4 ;
@@ -400,7 +408,8 @@ int iio_attr_get_available(const struct iio_attr *attr, char ***list, size_t *co
400408 while (token ) {
401409 if (n >= capacity ) {
402410 capacity *= 2 ;
403- char * * tmp = (char * * )realloc (local_list , capacity * sizeof (char * ));
411+ char * * tmp = (char * * )realloc (
412+ local_list , capacity * sizeof (char * ));
404413 if (!tmp ) {
405414 // Free previously allocated strings
406415 size_t i = 0 ;
@@ -418,7 +427,7 @@ int iio_attr_get_available(const struct iio_attr *attr, char ***list, size_t *co
418427 * list = local_list ;
419428 * count = n ;
420429
421- return 0 ;
430+ return 0 ;
422431}
423432
424433void iio_available_list_free (char * * list , size_t count )
@@ -434,7 +443,7 @@ void iio_available_list_free(char **list, size_t count)
434443}
435444
436445int iio_attr_get_available_buf (const struct iio_attr * attr , char * buf ,
437- size_t buflen , char * * list , size_t * count )
446+ size_t buflen , char * * list , size_t * count )
438447{
439448 ssize_t ret ;
440449 size_t n = 0 , max = (size_t )-1 ;
@@ -450,7 +459,8 @@ int iio_attr_get_available_buf(const struct iio_attr *attr, char *buf,
450459 if (list && count )
451460 max = * count ;
452461 else if (list && !count )
453- max = buflen / 2 + 1 ; // heuristic: max tokens if all single chars and spaces
462+ max = buflen / 2 +
463+ 1 ; // heuristic: max tokens if all single chars and spaces
454464
455465 ret = iio_attr_read_raw (attr , buf , buflen );
456466 if (ret < 0 )
0 commit comments