[rtems commit] libio: Simplify rtems_libio_iop()

Sebastian Huber sebh at rtems.org
Fri Sep 15 08:58:38 UTC 2017


Module:    rtems
Branch:    master
Commit:    7b4520258d1d449bd14c83a6b6490be8375e4a35
Changeset: http://git.rtems.org/rtems/commit/?id=7b4520258d1d449bd14c83a6b6490be8375e4a35

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed Sep 13 08:25:33 2017 +0200

libio: Simplify rtems_libio_iop()

Remove the file descriptor validation.  This is the job of
rtems_libio_check_fd().  Use an inline function instread of a macro.

Update #3132.

---

 cpukit/libcsupport/include/rtems/libio_.h | 20 +++++++++++++-------
 cpukit/libcsupport/src/fstat.c            |  2 +-
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/cpukit/libcsupport/include/rtems/libio_.h b/cpukit/libcsupport/include/rtems/libio_.h
index c2fb975..85f9c8e 100644
--- a/cpukit/libcsupport/include/rtems/libio_.h
+++ b/cpukit/libcsupport/include/rtems/libio_.h
@@ -89,15 +89,21 @@ extern rtems_filesystem_mount_table_entry_t rtems_filesystem_null_mt_entry;
  */
 extern rtems_filesystem_global_location_t rtems_filesystem_global_location_null;
 
-/*
- *  rtems_libio_iop
+/**
+ * @brief Maps a file descriptor to the iop.
+ *
+ * The file descriptor must be a valid index into the iop table.
+ *
+ * @param[in] fd The file descriptor.
  *
- *  Macro to return the file descriptor pointer.
+ * @return The iop corresponding to the specified file descriptor.
+ *
+ * @see rtems_libio_check_fd().
  */
-
-#define rtems_libio_iop(_fd) \
-  ((((uint32_t)(_fd)) < rtems_libio_number_iops) ? \
-         &rtems_libio_iops[_fd] : 0)
+static inline rtems_libio_t *rtems_libio_iop( int fd )
+{
+  return &rtems_libio_iops[ fd ];
+}
 
 /*
  *  rtems_libio_iop_to_descriptor
diff --git a/cpukit/libcsupport/src/fstat.c b/cpukit/libcsupport/src/fstat.c
index 8b39c43..4c284bd 100644
--- a/cpukit/libcsupport/src/fstat.c
+++ b/cpukit/libcsupport/src/fstat.c
@@ -36,8 +36,8 @@ int fstat(
   /*
    *  Now process the stat() request.
    */
-  iop = rtems_libio_iop( fd );
   rtems_libio_check_fd( fd );
+  iop = rtems_libio_iop( fd );
   rtems_libio_check_is_open(iop);
 
   /*



More information about the vc mailing list