4242 * Private Functions
4343 ****************************************************************************/
4444
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+
4558/****************************************************************************
4659 * Name: host_stat_convert
4760 ****************************************************************************/
@@ -196,7 +209,7 @@ int host_open(const char *pathname, int flags, int mode)
196209 int ret = open (pathname , mapflags , mode );
197210 if (ret == -1 )
198211 {
199- ret = - errno ;
212+ ret = host_errno_convert ( - errno ) ;
200213 }
201214
202215 return ret ;
@@ -213,7 +226,7 @@ int host_close(int fd)
213226 int ret = close (fd );
214227 if (ret == -1 )
215228 {
216- ret = - errno ;
229+ ret = host_errno_convert ( - errno ) ;
217230 }
218231
219232 return ret ;
@@ -230,7 +243,7 @@ nuttx_ssize_t host_read(int fd, void *buf, nuttx_size_t count)
230243 nuttx_ssize_t ret = read (fd , buf , count );
231244 if (ret == -1 )
232245 {
233- ret = - errno ;
246+ ret = host_errno_convert ( - errno ) ;
234247 }
235248
236249 return ret ;
@@ -247,7 +260,7 @@ nuttx_ssize_t host_write(int fd, const void *buf, nuttx_size_t count)
247260 nuttx_ssize_t ret = write (fd , buf , count );
248261 if (ret == -1 )
249262 {
250- ret = - errno ;
263+ ret = host_errno_convert ( - errno ) ;
251264 }
252265
253266 return ret ;
@@ -265,7 +278,7 @@ nuttx_off_t host_lseek(int fd, nuttx_off_t pos, nuttx_off_t offset,
265278 nuttx_off_t ret = lseek (fd , offset , whence );
266279 if (ret == (nuttx_off_t )- 1 )
267280 {
268- ret = - errno ;
281+ ret = host_errno_convert ( - errno ) ;
269282 }
270283
271284 return ret ;
@@ -279,7 +292,13 @@ int host_ioctl(int fd, int request, unsigned long arg)
279292{
280293 /* Just call the ioctl routine */
281294
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 ;
283302}
284303
285304/****************************************************************************
@@ -299,7 +318,13 @@ void host_sync(int fd)
299318
300319int host_dup (int fd )
301320{
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 ;
303328}
304329
305330/****************************************************************************
@@ -316,7 +341,7 @@ int host_fstat(int fd, struct nuttx_stat_s *buf)
316341 ret = fstat (fd , & hostbuf );
317342 if (ret < 0 )
318343 {
319- ret = - errno ;
344+ ret = host_errno_convert ( - errno ) ;
320345 }
321346
322347 /* Map the return values */
@@ -339,7 +364,7 @@ int host_fchstat(int fd, const struct nuttx_stat_s *buf, int flags)
339364 ret = fchmod (fd , buf -> st_mode );
340365 if (ret < 0 )
341366 {
342- return - errno ;
367+ return host_errno_convert ( - errno ) ;
343368 }
344369 }
345370
@@ -348,7 +373,7 @@ int host_fchstat(int fd, const struct nuttx_stat_s *buf, int flags)
348373 ret = fchown (fd , buf -> st_uid , buf -> st_gid );
349374 if (ret < 0 )
350375 {
351- return - errno ;
376+ return host_errno_convert ( - errno ) ;
352377 }
353378 }
354379
@@ -379,7 +404,7 @@ int host_fchstat(int fd, const struct nuttx_stat_s *buf, int flags)
379404 ret = futimens (fd , times );
380405 if (ret < 0 )
381406 {
382- return - errno ;
407+ return host_errno_convert ( - errno ) ;
383408 }
384409 }
385410
@@ -395,7 +420,7 @@ int host_ftruncate(int fd, nuttx_off_t length)
395420 int ret = ftruncate (fd , length );
396421 if (ret < 0 )
397422 {
398- ret = - errno ;
423+ ret = host_errno_convert ( - errno ) ;
399424 }
400425
401426 return ret ;
@@ -491,7 +516,7 @@ int host_closedir(void *dirp)
491516 int ret = closedir (dirp );
492517 if (ret < 0 )
493518 {
494- ret = - errno ;
519+ ret = host_errno_convert ( - errno ) ;
495520 }
496521
497522 return ret ;
@@ -511,7 +536,7 @@ int host_statfs(const char *path, struct nuttx_statfs_s *buf)
511536 ret = statvfs (path , & hostbuf );
512537 if (ret < 0 )
513538 {
514- ret = - errno ;
539+ ret = host_errno_convert ( - errno ) ;
515540 }
516541
517542 /* Map the struct statfs value */
@@ -537,7 +562,7 @@ int host_unlink(const char *pathname)
537562 int ret = unlink (pathname );
538563 if (ret < 0 )
539564 {
540- ret = - errno ;
565+ ret = host_errno_convert ( - errno ) ;
541566 }
542567
543568 return ret ;
@@ -554,7 +579,7 @@ int host_mkdir(const char *pathname, int mode)
554579 int ret = mkdir (pathname , mode );
555580 if (ret < 0 )
556581 {
557- ret = - errno ;
582+ ret = host_errno_convert ( - errno ) ;
558583 }
559584
560585 return ret ;
@@ -569,7 +594,7 @@ int host_rmdir(const char *pathname)
569594 int ret = rmdir (pathname );
570595 if (ret < 0 )
571596 {
572- ret = - errno ;
597+ ret = host_errno_convert ( - errno ) ;
573598 }
574599
575600 return ret ;
@@ -584,7 +609,7 @@ int host_rename(const char *oldpath, const char *newpath)
584609 int ret = rename (oldpath , newpath );
585610 if (ret < 0 )
586611 {
587- ret = - errno ;
612+ ret = host_errno_convert ( - errno ) ;
588613 }
589614
590615 return ret ;
@@ -604,7 +629,7 @@ int host_stat(const char *path, struct nuttx_stat_s *buf)
604629 ret = stat (path , & hostbuf );
605630 if (ret < 0 )
606631 {
607- ret = - errno ;
632+ ret = host_errno_convert ( - errno ) ;
608633 }
609634
610635 /* Map the return values */
@@ -627,7 +652,7 @@ int host_chstat(const char *path, const struct nuttx_stat_s *buf, int flags)
627652 ret = chmod (path , buf -> st_mode );
628653 if (ret < 0 )
629654 {
630- return - errno ;
655+ return host_errno_convert ( - errno ) ;
631656 }
632657 }
633658
@@ -636,7 +661,7 @@ int host_chstat(const char *path, const struct nuttx_stat_s *buf, int flags)
636661 ret = chown (path , buf -> st_uid , buf -> st_gid );
637662 if (ret < 0 )
638663 {
639- return - errno ;
664+ return host_errno_convert ( - errno ) ;
640665 }
641666 }
642667
@@ -667,7 +692,7 @@ int host_chstat(const char *path, const struct nuttx_stat_s *buf, int flags)
667692 ret = utimensat (AT_FDCWD , path , times , 0 );
668693 if (ret < 0 )
669694 {
670- return - errno ;
695+ return host_errno_convert ( - errno ) ;
671696 }
672697 }
673698
0 commit comments