42
42
* Private Functions
43
43
****************************************************************************/
44
44
45
+ /****************************************************************************
46
+ * Name: host_errno_convert
47
+ ****************************************************************************/
48
+
49
+ static int host_errno_convert (int errcode )
50
+ {
51
+ /* Provide a common interface, which should have different conversions
52
+ * on different platforms.
53
+ */
54
+
55
+ return errcode ;
56
+ }
57
+
45
58
/****************************************************************************
46
59
* Name: host_stat_convert
47
60
****************************************************************************/
@@ -196,7 +209,7 @@ int host_open(const char *pathname, int flags, int mode)
196
209
int ret = open (pathname , mapflags , mode );
197
210
if (ret == -1 )
198
211
{
199
- ret = - errno ;
212
+ ret = host_errno_convert ( - errno ) ;
200
213
}
201
214
202
215
return ret ;
@@ -213,7 +226,7 @@ int host_close(int fd)
213
226
int ret = close (fd );
214
227
if (ret == -1 )
215
228
{
216
- ret = - errno ;
229
+ ret = host_errno_convert ( - errno ) ;
217
230
}
218
231
219
232
return ret ;
@@ -230,7 +243,7 @@ nuttx_ssize_t host_read(int fd, void *buf, nuttx_size_t count)
230
243
nuttx_ssize_t ret = read (fd , buf , count );
231
244
if (ret == -1 )
232
245
{
233
- ret = - errno ;
246
+ ret = host_errno_convert ( - errno ) ;
234
247
}
235
248
236
249
return ret ;
@@ -247,7 +260,7 @@ nuttx_ssize_t host_write(int fd, const void *buf, nuttx_size_t count)
247
260
nuttx_ssize_t ret = write (fd , buf , count );
248
261
if (ret == -1 )
249
262
{
250
- ret = - errno ;
263
+ ret = host_errno_convert ( - errno ) ;
251
264
}
252
265
253
266
return ret ;
@@ -265,7 +278,7 @@ nuttx_off_t host_lseek(int fd, nuttx_off_t pos, nuttx_off_t offset,
265
278
nuttx_off_t ret = lseek (fd , offset , whence );
266
279
if (ret == (nuttx_off_t )- 1 )
267
280
{
268
- ret = - errno ;
281
+ ret = host_errno_convert ( - errno ) ;
269
282
}
270
283
271
284
return ret ;
@@ -279,7 +292,13 @@ int host_ioctl(int fd, int request, unsigned long arg)
279
292
{
280
293
/* Just call the ioctl routine */
281
294
282
- return ioctl (fd , request , arg );
295
+ int ret = ioctl (fd , request , arg );
296
+ if (ret < 0 )
297
+ {
298
+ ret = host_errno_convert (- errno );
299
+ }
300
+
301
+ return ret ;
283
302
}
284
303
285
304
/****************************************************************************
@@ -299,7 +318,13 @@ void host_sync(int fd)
299
318
300
319
int host_dup (int fd )
301
320
{
302
- return dup (fd );
321
+ int ret = dup (fd );
322
+ if (ret < 0 )
323
+ {
324
+ ret = host_errno_convert (- errno );
325
+ }
326
+
327
+ return ret ;
303
328
}
304
329
305
330
/****************************************************************************
@@ -316,7 +341,7 @@ int host_fstat(int fd, struct nuttx_stat_s *buf)
316
341
ret = fstat (fd , & hostbuf );
317
342
if (ret < 0 )
318
343
{
319
- ret = - errno ;
344
+ ret = host_errno_convert ( - errno ) ;
320
345
}
321
346
322
347
/* Map the return values */
@@ -339,7 +364,7 @@ int host_fchstat(int fd, const struct nuttx_stat_s *buf, int flags)
339
364
ret = fchmod (fd , buf -> st_mode );
340
365
if (ret < 0 )
341
366
{
342
- return - errno ;
367
+ return host_errno_convert ( - errno ) ;
343
368
}
344
369
}
345
370
@@ -348,7 +373,7 @@ int host_fchstat(int fd, const struct nuttx_stat_s *buf, int flags)
348
373
ret = fchown (fd , buf -> st_uid , buf -> st_gid );
349
374
if (ret < 0 )
350
375
{
351
- return - errno ;
376
+ return host_errno_convert ( - errno ) ;
352
377
}
353
378
}
354
379
@@ -379,7 +404,7 @@ int host_fchstat(int fd, const struct nuttx_stat_s *buf, int flags)
379
404
ret = futimens (fd , times );
380
405
if (ret < 0 )
381
406
{
382
- return - errno ;
407
+ return host_errno_convert ( - errno ) ;
383
408
}
384
409
}
385
410
@@ -395,7 +420,7 @@ int host_ftruncate(int fd, nuttx_off_t length)
395
420
int ret = ftruncate (fd , length );
396
421
if (ret < 0 )
397
422
{
398
- ret = - errno ;
423
+ ret = host_errno_convert ( - errno ) ;
399
424
}
400
425
401
426
return ret ;
@@ -491,7 +516,7 @@ int host_closedir(void *dirp)
491
516
int ret = closedir (dirp );
492
517
if (ret < 0 )
493
518
{
494
- ret = - errno ;
519
+ ret = host_errno_convert ( - errno ) ;
495
520
}
496
521
497
522
return ret ;
@@ -511,7 +536,7 @@ int host_statfs(const char *path, struct nuttx_statfs_s *buf)
511
536
ret = statvfs (path , & hostbuf );
512
537
if (ret < 0 )
513
538
{
514
- ret = - errno ;
539
+ ret = host_errno_convert ( - errno ) ;
515
540
}
516
541
517
542
/* Map the struct statfs value */
@@ -537,7 +562,7 @@ int host_unlink(const char *pathname)
537
562
int ret = unlink (pathname );
538
563
if (ret < 0 )
539
564
{
540
- ret = - errno ;
565
+ ret = host_errno_convert ( - errno ) ;
541
566
}
542
567
543
568
return ret ;
@@ -554,7 +579,7 @@ int host_mkdir(const char *pathname, int mode)
554
579
int ret = mkdir (pathname , mode );
555
580
if (ret < 0 )
556
581
{
557
- ret = - errno ;
582
+ ret = host_errno_convert ( - errno ) ;
558
583
}
559
584
560
585
return ret ;
@@ -569,7 +594,7 @@ int host_rmdir(const char *pathname)
569
594
int ret = rmdir (pathname );
570
595
if (ret < 0 )
571
596
{
572
- ret = - errno ;
597
+ ret = host_errno_convert ( - errno ) ;
573
598
}
574
599
575
600
return ret ;
@@ -584,7 +609,7 @@ int host_rename(const char *oldpath, const char *newpath)
584
609
int ret = rename (oldpath , newpath );
585
610
if (ret < 0 )
586
611
{
587
- ret = - errno ;
612
+ ret = host_errno_convert ( - errno ) ;
588
613
}
589
614
590
615
return ret ;
@@ -604,7 +629,7 @@ int host_stat(const char *path, struct nuttx_stat_s *buf)
604
629
ret = stat (path , & hostbuf );
605
630
if (ret < 0 )
606
631
{
607
- ret = - errno ;
632
+ ret = host_errno_convert ( - errno ) ;
608
633
}
609
634
610
635
/* Map the return values */
@@ -627,7 +652,7 @@ int host_chstat(const char *path, const struct nuttx_stat_s *buf, int flags)
627
652
ret = chmod (path , buf -> st_mode );
628
653
if (ret < 0 )
629
654
{
630
- return - errno ;
655
+ return host_errno_convert ( - errno ) ;
631
656
}
632
657
}
633
658
@@ -636,7 +661,7 @@ int host_chstat(const char *path, const struct nuttx_stat_s *buf, int flags)
636
661
ret = chown (path , buf -> st_uid , buf -> st_gid );
637
662
if (ret < 0 )
638
663
{
639
- return - errno ;
664
+ return host_errno_convert ( - errno ) ;
640
665
}
641
666
}
642
667
@@ -667,7 +692,7 @@ int host_chstat(const char *path, const struct nuttx_stat_s *buf, int flags)
667
692
ret = utimensat (AT_FDCWD , path , times , 0 );
668
693
if (ret < 0 )
669
694
{
670
- return - errno ;
695
+ return host_errno_convert ( - errno ) ;
671
696
}
672
697
}
673
698
0 commit comments