diff --git a/arch/sim/src/sim/posix/sim_hostfs.c b/arch/sim/src/sim/posix/sim_hostfs.c index 798b4a3c62980..5ead9cdfb50db 100644 --- a/arch/sim/src/sim/posix/sim_hostfs.c +++ b/arch/sim/src/sim/posix/sim_hostfs.c @@ -42,6 +42,19 @@ * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: host_errno_convert + ****************************************************************************/ + +static int host_errno_convert(int errcode) +{ + /* Provide a common interface, which should have different conversions + * on different platforms. + */ + + return errcode; +} + /**************************************************************************** * Name: host_stat_convert ****************************************************************************/ @@ -196,7 +209,7 @@ int host_open(const char *pathname, int flags, int mode) int ret = open(pathname, mapflags, mode); if (ret == -1) { - ret = -errno; + ret = host_errno_convert(-errno); } return ret; @@ -213,7 +226,7 @@ int host_close(int fd) int ret = close(fd); if (ret == -1) { - ret = -errno; + ret = host_errno_convert(-errno); } return ret; @@ -230,7 +243,7 @@ nuttx_ssize_t host_read(int fd, void *buf, nuttx_size_t count) nuttx_ssize_t ret = read(fd, buf, count); if (ret == -1) { - ret = -errno; + ret = host_errno_convert(-errno); } return ret; @@ -247,7 +260,7 @@ nuttx_ssize_t host_write(int fd, const void *buf, nuttx_size_t count) nuttx_ssize_t ret = write(fd, buf, count); if (ret == -1) { - ret = -errno; + ret = host_errno_convert(-errno); } return ret; @@ -265,7 +278,7 @@ nuttx_off_t host_lseek(int fd, nuttx_off_t pos, nuttx_off_t offset, nuttx_off_t ret = lseek(fd, offset, whence); if (ret == (nuttx_off_t)-1) { - ret = -errno; + ret = host_errno_convert(-errno); } return ret; @@ -279,7 +292,13 @@ int host_ioctl(int fd, int request, unsigned long arg) { /* Just call the ioctl routine */ - return ioctl(fd, request, arg); + int ret = ioctl(fd, request, arg); + if (ret < 0) + { + ret = host_errno_convert(-errno); + } + + return ret; } /**************************************************************************** @@ -299,7 +318,13 @@ void host_sync(int fd) int host_dup(int fd) { - return dup(fd); + int ret = dup(fd); + if (ret < 0) + { + ret = host_errno_convert(-errno); + } + + return ret; } /**************************************************************************** @@ -316,7 +341,7 @@ int host_fstat(int fd, struct nuttx_stat_s *buf) ret = fstat(fd, &hostbuf); if (ret < 0) { - ret = -errno; + ret = host_errno_convert(-errno); } /* Map the return values */ @@ -339,7 +364,7 @@ int host_fchstat(int fd, const struct nuttx_stat_s *buf, int flags) ret = fchmod(fd, buf->st_mode); if (ret < 0) { - return -errno; + return host_errno_convert(-errno); } } @@ -348,7 +373,7 @@ int host_fchstat(int fd, const struct nuttx_stat_s *buf, int flags) ret = fchown(fd, buf->st_uid, buf->st_gid); if (ret < 0) { - return -errno; + return host_errno_convert(-errno); } } @@ -379,7 +404,7 @@ int host_fchstat(int fd, const struct nuttx_stat_s *buf, int flags) ret = futimens(fd, times); if (ret < 0) { - return -errno; + return host_errno_convert(-errno); } } @@ -395,7 +420,7 @@ int host_ftruncate(int fd, nuttx_off_t length) int ret = ftruncate(fd, length); if (ret < 0) { - ret = -errno; + ret = host_errno_convert(-errno); } return ret; @@ -491,7 +516,7 @@ int host_closedir(void *dirp) int ret = closedir(dirp); if (ret < 0) { - ret = -errno; + ret = host_errno_convert(-errno); } return ret; @@ -511,7 +536,7 @@ int host_statfs(const char *path, struct nuttx_statfs_s *buf) ret = statvfs(path, &hostbuf); if (ret < 0) { - ret = -errno; + ret = host_errno_convert(-errno); } /* Map the struct statfs value */ @@ -537,7 +562,7 @@ int host_unlink(const char *pathname) int ret = unlink(pathname); if (ret < 0) { - ret = -errno; + ret = host_errno_convert(-errno); } return ret; @@ -554,7 +579,7 @@ int host_mkdir(const char *pathname, int mode) int ret = mkdir(pathname, mode); if (ret < 0) { - ret = -errno; + ret = host_errno_convert(-errno); } return ret; @@ -569,7 +594,7 @@ int host_rmdir(const char *pathname) int ret = rmdir(pathname); if (ret < 0) { - ret = -errno; + ret = host_errno_convert(-errno); } return ret; @@ -584,7 +609,7 @@ int host_rename(const char *oldpath, const char *newpath) int ret = rename(oldpath, newpath); if (ret < 0) { - ret = -errno; + ret = host_errno_convert(-errno); } return ret; @@ -604,7 +629,7 @@ int host_stat(const char *path, struct nuttx_stat_s *buf) ret = stat(path, &hostbuf); if (ret < 0) { - ret = -errno; + ret = host_errno_convert(-errno); } /* Map the return values */ @@ -627,7 +652,7 @@ int host_chstat(const char *path, const struct nuttx_stat_s *buf, int flags) ret = chmod(path, buf->st_mode); if (ret < 0) { - return -errno; + return host_errno_convert(-errno); } } @@ -636,7 +661,7 @@ int host_chstat(const char *path, const struct nuttx_stat_s *buf, int flags) ret = chown(path, buf->st_uid, buf->st_gid); if (ret < 0) { - return -errno; + return host_errno_convert(-errno); } } @@ -667,7 +692,7 @@ int host_chstat(const char *path, const struct nuttx_stat_s *buf, int flags) ret = utimensat(AT_FDCWD, path, times, 0); if (ret < 0) { - return -errno; + return host_errno_convert(-errno); } }