3535#include <nuttx/streams.h>
3636#include <uORB/uORB.h>
3737
38+ /****************************************************************************
39+ * Pre-processor Definitions
40+ ****************************************************************************/
41+
42+ #define ORB_IOCTL (fd , cmd , arg ) \
43+ do \
44+ { \
45+ if (ioctl(fd, cmd, arg) < 0) \
46+ { \
47+ return -errno; \
48+ } \
49+ \
50+ } \
51+ while (0)
52+
3853/****************************************************************************
3954 * Private Functions
4055 ****************************************************************************/
5469 * non_wakeup The non wakeup flag.
5570 *
5671 * Returned Value:
57- * fd on success, otherwise returns negative value and set errno .
72+ * fd on success, otherwise returns a negated errno value on failure .
5873 ****************************************************************************/
5974
6075static int orb_advsub_open (FAR const struct orb_metadata * meta , int flags ,
@@ -76,6 +91,7 @@ static int orb_advsub_open(FAR const struct orb_metadata *meta, int flags,
7691 if (fd < 0 )
7792 {
7893 struct sensor_reginfo_s reginfo ;
94+
7995 strlcpy (reginfo .path , path , NAME_MAX );
8096 reginfo .esize = meta -> o_size ;
8197 reginfo .nbuffer = queue_size ;
@@ -92,7 +108,7 @@ static int orb_advsub_open(FAR const struct orb_metadata *meta, int flags,
92108 fd = open (ORB_USENSOR_PATH , O_WRONLY | O_CLOEXEC );
93109 if (fd < 0 )
94110 {
95- return fd ;
111+ return - errno ;
96112 }
97113
98114 /* Register new device node */
@@ -102,13 +118,13 @@ static int orb_advsub_open(FAR const struct orb_metadata *meta, int flags,
102118 close (fd );
103119 if (ret < 0 && err != EEXIST )
104120 {
105- return ret ;
121+ return - err ;
106122 }
107123
108124 fd = open (path , flags );
109125 if (fd < 0 )
110126 {
111- return fd ;
127+ return - errno ;
112128 }
113129
114130 if (err != EEXIST )
@@ -177,15 +193,30 @@ orb_advertise_multi_queue_flags(FAR const struct orb_metadata *meta,
177193
178194int orb_open (FAR const char * name , int instance , int flags )
179195{
196+ int ret ;
180197 char path [ORB_PATH_MAX ];
181198
182199 snprintf (path , ORB_PATH_MAX , ORB_SENSOR_PATH "%s%d" , name , instance );
183- return open (path , O_CLOEXEC | flags );
200+ ret = open (path , O_CLOEXEC | flags );
201+ if (ret < 0 )
202+ {
203+ return - errno ;
204+ }
205+
206+ return ret ;
184207}
185208
186209int orb_close (int fd )
187210{
188- return close (fd );
211+ int ret ;
212+
213+ ret = close (fd );
214+ if (ret < 0 )
215+ {
216+ return - errno ;
217+ }
218+
219+ return ret ;
189220}
190221
191222int orb_advertise_multi_queue_info (FAR const struct orb_metadata * meta ,
@@ -210,7 +241,15 @@ orb_advertise_multi_queue_persist_info(FAR const struct orb_metadata *meta,
210241
211242ssize_t orb_publish_multi (int fd , FAR const void * data , size_t len )
212243{
213- return write (fd , data , len );
244+ ssize_t ret ;
245+
246+ ret = write (fd , data , len );
247+ if (ret < 0 )
248+ {
249+ return - errno ;
250+ }
251+
252+ return ret ;
214253}
215254
216255int orb_subscribe_multi (FAR const struct orb_metadata * meta ,
@@ -227,33 +266,34 @@ int orb_subscribe_multi_nonwakeup(FAR const struct orb_metadata *meta,
227266
228267ssize_t orb_copy_multi (int fd , FAR void * buffer , size_t len )
229268{
230- return read (fd , buffer , len );
269+ ssize_t ret ;
270+
271+ ret = read (fd , buffer , len );
272+ if (ret < 0 )
273+ {
274+ return - errno ;
275+ }
276+
277+ return ret ;
231278}
232279
233280int orb_get_state (int fd , FAR struct orb_state * state )
234281{
235282 struct sensor_state_s tmp ;
236- int ret ;
237283
238284 if (!state )
239285 {
240286 return - EINVAL ;
241287 }
242288
243- ret = ioctl (fd , SNIOC_GET_STATE , (unsigned long )(uintptr_t )& tmp );
244- if (ret < 0 )
245- {
246- return ret ;
247- }
248-
289+ ORB_IOCTL (fd , SNIOC_GET_STATE , (unsigned long )(uintptr_t )& tmp );
249290 state -> max_frequency = tmp .min_interval ?
250291 1000000 / tmp .min_interval : 0 ;
251292 state -> min_batch_interval = tmp .min_latency ;
252293 state -> queue_size = tmp .nbuffer ;
253294 state -> nsubscribers = tmp .nsubscribers ;
254295 state -> generation = tmp .generation ;
255-
256- return ret ;
296+ return 0 ;
257297}
258298
259299int orb_get_events (int fd , FAR unsigned int * events )
@@ -263,67 +303,62 @@ int orb_get_events(int fd, FAR unsigned int *events)
263303 return - EINVAL ;
264304 }
265305
266- return ioctl (fd , SNIOC_GET_EVENTS , (unsigned long )(uintptr_t )events );
306+ ORB_IOCTL (fd , SNIOC_GET_EVENTS , (unsigned long )(uintptr_t )events );
307+ return 0 ;
267308}
268309
269310int orb_check (int fd , FAR bool * updated )
270311{
271- return ioctl (fd , SNIOC_UPDATED , (unsigned long )(uintptr_t )updated );
312+ ORB_IOCTL (fd , SNIOC_UPDATED , (unsigned long )(uintptr_t )updated );
313+ return 0 ;
272314}
273315
274316int orb_ioctl (int fd , int cmd , unsigned long arg )
275317{
276- return ioctl (fd , cmd , arg );
318+ ORB_IOCTL (fd , cmd , arg );
319+ return 0 ;
277320}
278321
279322int orb_flush (int fd )
280323{
281- return ioctl (fd , SNIOC_FLUSH , 0 );
324+ ORB_IOCTL (fd , SNIOC_FLUSH , 0 );
325+ return 0 ;
282326}
283327
284328int orb_set_interval (int fd , unsigned interval )
285329{
286- return ioctl (fd , SNIOC_SET_INTERVAL , (unsigned long )interval );
330+ ORB_IOCTL (fd , SNIOC_SET_INTERVAL , (unsigned long )interval );
331+ return 0 ;
287332}
288333
289334int orb_get_interval (int fd , FAR unsigned * interval )
290335{
291336 struct sensor_ustate_s tmp ;
292- int ret ;
293-
294- ret = ioctl (fd , SNIOC_GET_USTATE , (unsigned long )(uintptr_t )& tmp );
295- if (ret < 0 )
296- {
297- return ret ;
298- }
299337
338+ ORB_IOCTL (fd , SNIOC_GET_USTATE , (unsigned long )(uintptr_t )& tmp );
300339 * interval = tmp .interval ;
301- return ret ;
340+ return 0 ;
302341}
303342
304343int orb_get_info (int fd , FAR orb_info_t * info )
305344{
306- return ioctl (fd , SNIOC_GET_INFO , (unsigned long )(uintptr_t )info );
345+ ORB_IOCTL (fd , SNIOC_GET_INFO , (unsigned long )(uintptr_t )info );
346+ return 0 ;
307347}
308348
309349int orb_set_batch_interval (int fd , unsigned batch_interval )
310350{
311- return ioctl (fd , SNIOC_BATCH , (unsigned long )batch_interval );
351+ ORB_IOCTL (fd , SNIOC_BATCH , (unsigned long )batch_interval );
352+ return 0 ;
312353}
313354
314355int orb_get_batch_interval (int fd , FAR unsigned * batch_interval )
315356{
316357 struct sensor_ustate_s tmp ;
317- int ret ;
318-
319- ret = ioctl (fd , SNIOC_GET_USTATE , (unsigned long )(uintptr_t )& tmp );
320- if (ret < 0 )
321- {
322- return ret ;
323- }
324358
359+ ORB_IOCTL (fd , SNIOC_GET_USTATE , (unsigned long )(uintptr_t )& tmp );
325360 * batch_interval = tmp .latency ;
326- return ret ;
361+ return 0 ;
327362}
328363
329364orb_abstime orb_absolute_time (void )
@@ -347,14 +382,14 @@ int orb_exists(FAR const struct orb_metadata *meta, int instance)
347382 fd = open (path , 0 );
348383 if (fd < 0 )
349384 {
350- return -1 ;
385+ return - errno ;
351386 }
352387
353388 ret = ioctl (fd , SNIOC_GET_STATE , (unsigned long )(uintptr_t )& state );
354389 close (fd );
355390 if (ret < 0 )
356391 {
357- return -1 ;
392+ return - errno ;
358393 }
359394
360395 return state .nadvertisers > 0 ? 0 : -1 ;
0 commit comments