[PATCH 15/18] libio: Add rtems_libio_iop_is_append()

Sebastian Huber sebastian.huber at embedded-brains.de
Wed Sep 13 13:39:48 UTC 2017


Update #3082.
---
 cpukit/libcsupport/include/rtems/libio.h    | 10 ++++++++++
 cpukit/libfs/src/dosfs/msdos_file.c         |  2 +-
 cpukit/libfs/src/imfs/imfs_memfile.c        |  2 +-
 cpukit/libfs/src/jffs2/src/fs-rtems.c       |  6 +++---
 cpukit/libfs/src/nfsclient/src/nfs.c        |  2 +-
 cpukit/libfs/src/rfs/rtems-rfs-rtems-file.c |  2 +-
 6 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/cpukit/libcsupport/include/rtems/libio.h b/cpukit/libcsupport/include/rtems/libio.h
index 72a787eebc..2a67496800 100644
--- a/cpukit/libcsupport/include/rtems/libio.h
+++ b/cpukit/libcsupport/include/rtems/libio.h
@@ -1410,6 +1410,16 @@ static inline bool rtems_libio_iop_is_writeable( const rtems_libio_t *iop )
 }
 
 /**
+ * @brief Returns true if this is an append iop, otherwise returns false.
+ *
+ * @param[in] iop The iop.
+ */
+static inline bool rtems_libio_iop_is_append( const rtems_libio_t *iop )
+{
+  return ( rtems_libio_iop_flags( iop ) & LIBIO_FLAGS_APPEND ) != 0;
+}
+
+/**
  * @name External I/O Handlers
  */
 /**@{**/
diff --git a/cpukit/libfs/src/dosfs/msdos_file.c b/cpukit/libfs/src/dosfs/msdos_file.c
index ada943d854..d150a1ff22 100644
--- a/cpukit/libfs/src/dosfs/msdos_file.c
+++ b/cpukit/libfs/src/dosfs/msdos_file.c
@@ -91,7 +91,7 @@ msdos_file_write(rtems_libio_t *iop,const void *buffer, size_t count)
     if (sc != RTEMS_SUCCESSFUL)
         rtems_set_errno_and_return_minus_one(EIO);
 
-    if ((iop->flags & LIBIO_FLAGS_APPEND) != 0)
+    if (rtems_libio_iop_is_append(iop))
         iop->offset = fat_fd->fat_file_size;
 
     ret = fat_file_write(&fs_info->fat, fat_fd, iop->offset, count,
diff --git a/cpukit/libfs/src/imfs/imfs_memfile.c b/cpukit/libfs/src/imfs/imfs_memfile.c
index 2227bba6af..9e3474bc86 100644
--- a/cpukit/libfs/src/imfs/imfs_memfile.c
+++ b/cpukit/libfs/src/imfs/imfs_memfile.c
@@ -87,7 +87,7 @@ static ssize_t memfile_write(
   IMFS_memfile_t *memfile = IMFS_iop_to_memfile( iop );
   ssize_t         status;
 
-  if ((iop->flags & LIBIO_FLAGS_APPEND) != 0)
+  if (rtems_libio_iop_is_append(iop))
     iop->offset = memfile->File.size;
 
   status = IMFS_memfile_write( memfile, iop->offset, buffer, count );
diff --git a/cpukit/libfs/src/jffs2/src/fs-rtems.c b/cpukit/libfs/src/jffs2/src/fs-rtems.c
index 5e702ce5ec..262bec9b27 100644
--- a/cpukit/libfs/src/jffs2/src/fs-rtems.c
+++ b/cpukit/libfs/src/jffs2/src/fs-rtems.c
@@ -672,10 +672,10 @@ static ssize_t rtems_jffs2_file_write(rtems_libio_t *iop, const void *buf, size_
 
 	rtems_jffs2_do_lock(inode->i_sb);
 
-	if ((iop->flags & LIBIO_FLAGS_APPEND) == 0) {
-		pos = iop->offset;
-	} else {
+	if (rtems_libio_iop_is_append(iop)) {
 		pos = inode->i_size;
+	} else {
+		pos = iop->offset;
 	}
 
 	if (pos > inode->i_size) {
diff --git a/cpukit/libfs/src/nfsclient/src/nfs.c b/cpukit/libfs/src/nfsclient/src/nfs.c
index 87fef54ac0..ca4226465a 100644
--- a/cpukit/libfs/src/nfsclient/src/nfs.c
+++ b/cpukit/libfs/src/nfsclient/src/nfs.c
@@ -2566,7 +2566,7 @@ Nfs			nfs  = node->nfs;
 
 
 	SERP_ARGS(node).writearg.beginoffset = UINT32_C(0xdeadbeef);
-	if ( LIBIO_FLAGS_APPEND & iop->flags ) {
+	if (rtems_libio_iop_is_append(iop)) {
 		if ( updateAttr(node, 0) ) {
 			return -1;
 		}
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-rtems-file.c b/cpukit/libfs/src/rfs/rtems-rfs-rtems-file.c
index 99782db72b..69e5df2a97 100644
--- a/cpukit/libfs/src/rfs/rtems-rfs-rtems-file.c
+++ b/cpukit/libfs/src/rfs/rtems-rfs-rtems-file.c
@@ -208,7 +208,7 @@ rtems_rfs_rtems_file_write (rtems_libio_t* iop,
 
     rtems_rfs_file_set_bpos (file, pos);
   }
-  else if (pos < file_size && (iop->flags & LIBIO_FLAGS_APPEND) != 0)
+  else if (pos < file_size && rtems_libio_iop_is_append(iop))
   {
     pos = file_size;
     rc = rtems_rfs_file_seek (file, pos, &pos);
-- 
2.12.3




More information about the devel mailing list