Index: cpukit/libcsupport/include/rtems/libio_.h
===================================================================
--- cpukit/libcsupport/include/rtems/libio_.h	(revision 856ede4f91a76a1a681ceac24ddb18d3a438dffb)
+++ cpukit/libcsupport/include/rtems/libio_.h	(revision ca90c6c1db3881ce5a44e06610a29a128e5455f2)
@@ -89,4 +89,22 @@
  */
 extern rtems_filesystem_global_location_t rtems_filesystem_global_location_null;
+
+/**
+ * @brief Sets the iop flags to the specified flags together with
+ * LIBIO_FLAGS_OPEN.
+ *
+ * Use this once a file descriptor allocated via rtems_libio_allocate() is
+ * fully initialized.
+ *
+ * @param[in] iop The iop.
+ * @param[in] flags The flags.
+ */
+static inline void rtems_libio_iop_flags_initialize(
+  rtems_libio_t *iop,
+  uint32_t       flags
+)
+{
+  iop->flags = LIBIO_FLAGS_OPEN | flags;
+}
 
 /**
Index: cpukit/libcsupport/src/fcntl.c
===================================================================
--- cpukit/libcsupport/src/fcntl.c	(revision 856ede4f91a76a1a681ceac24ddb18d3a438dffb)
+++ cpukit/libcsupport/src/fcntl.c	(revision ca90c6c1db3881ce5a44e06610a29a128e5455f2)
@@ -27,13 +27,12 @@
 static int duplicate_iop( rtems_libio_t *iop )
 {
-  int rv = 0;
-
-  rtems_libio_t *diop = rtems_libio_allocate();
+  int            rv;
+  int            oflag;
+  rtems_libio_t *diop;
+
+  oflag = rtems_libio_to_fcntl_flags( iop->flags );
+  diop = rtems_libio_allocate();
 
   if (diop != NULL) {
-    int oflag = rtems_libio_to_fcntl_flags( iop->flags );
-
-    rtems_libio_iop_flags_set( diop, rtems_libio_fcntl_flags( oflag ) );
-
     rtems_filesystem_instance_lock( &iop->pathinfo );
     rtems_filesystem_location_clone( &diop->pathinfo, &iop->pathinfo );
@@ -47,4 +46,8 @@
     rv = (*diop->pathinfo.handlers->open_h)( diop, NULL, oflag, 0 );
     if ( rv == 0 ) {
+      rtems_libio_iop_flags_initialize(
+        diop,
+        rtems_libio_fcntl_flags( oflag )
+      );
       rv = rtems_libio_iop_to_descriptor( diop );
     } else {
Index: cpukit/libcsupport/src/libio.c
===================================================================
--- cpukit/libcsupport/src/libio.c	(revision 856ede4f91a76a1a681ceac24ddb18d3a438dffb)
+++ cpukit/libcsupport/src/libio.c	(revision ca90c6c1db3881ce5a44e06610a29a128e5455f2)
@@ -117,5 +117,4 @@
     rtems_libio_iop_freelist = iop->data1;
     memset( iop, 0, sizeof(*iop) );
-    iop->flags = LIBIO_FLAGS_OPEN;
   }
 
Index: cpukit/libcsupport/src/open.c
===================================================================
--- cpukit/libcsupport/src/open.c	(revision 856ede4f91a76a1a681ceac24ddb18d3a438dffb)
+++ cpukit/libcsupport/src/open.c	(revision ca90c6c1db3881ce5a44e06610a29a128e5455f2)
@@ -97,11 +97,14 @@
   }
 
-  rtems_libio_iop_flags_set( iop, rtems_libio_fcntl_flags( oflag ) );
   rtems_filesystem_eval_path_extract_currentloc( &ctx, &iop->pathinfo );
   rtems_filesystem_eval_path_cleanup( &ctx );
+
+  iop->flags = rtems_libio_fcntl_flags( oflag );
 
   rv = (*iop->pathinfo.handlers->open_h)( iop, path, oflag, mode );
 
   if ( rv == 0 ) {
+    rtems_libio_iop_flags_set( iop, LIBIO_FLAGS_OPEN );
+
     if ( truncate ) {
       rv = ftruncate( fd, 0 );
Index: cpukit/libnetworking/rtems/rtems_syscall.c
===================================================================
--- cpukit/libnetworking/rtems/rtems_syscall.c	(revision 856ede4f91a76a1a681ceac24ddb18d3a438dffb)
+++ cpukit/libnetworking/rtems/rtems_syscall.c	(revision ca90c6c1db3881ce5a44e06610a29a128e5455f2)
@@ -82,5 +82,4 @@
 
   fd = rtems_libio_iop_to_descriptor(iop);
-  rtems_libio_iop_flags_set(iop, LIBIO_FLAGS_READ_WRITE);
   iop->data0 = fd;
   iop->data1 = so;
@@ -88,4 +87,5 @@
   iop->pathinfo.mt_entry = &rtems_filesystem_null_mt_entry;
   rtems_filesystem_location_add_to_mt_entry(&iop->pathinfo);
+  rtems_libio_iop_flags_initialize(iop, LIBIO_FLAGS_READ_WRITE);
   return fd;
 }
Index: cpukit/posix/src/shmopen.c
===================================================================
--- cpukit/posix/src/shmopen.c	(revision 856ede4f91a76a1a681ceac24ddb18d3a438dffb)
+++ cpukit/posix/src/shmopen.c	(revision ca90c6c1db3881ce5a44e06610a29a128e5455f2)
@@ -226,4 +226,5 @@
   size_t len;
   Objects_Get_by_name_error obj_err;
+  uint32_t flags;
 
   if ( shm_check_oflag( oflag ) != 0 ) {
@@ -276,10 +277,4 @@
 
   fd = rtems_libio_iop_to_descriptor( iop );
-  rtems_libio_iop_flags_set( iop, LIBIO_FLAGS_CLOSE_ON_EXEC );
-  if ( oflag & O_RDONLY ) {
-    rtems_libio_iop_flags_set( iop, LIBIO_FLAGS_READ );
-  } else {
-    rtems_libio_iop_flags_set( iop, LIBIO_FLAGS_READ_WRITE );
-  }
   iop->data0 = fd;
   iop->data1 = shm;
@@ -288,4 +283,13 @@
   iop->pathinfo.mt_entry = &rtems_filesystem_null_mt_entry;
   rtems_filesystem_location_add_to_mt_entry( &iop->pathinfo );
+
+  flags = LIBIO_FLAGS_CLOSE_ON_EXEC;
+  if ( oflag & O_RDONLY ) {
+    flags |= LIBIO_FLAGS_READ;
+  } else {
+    flags |= LIBIO_FLAGS_READ_WRITE;
+  }
+
+  rtems_libio_iop_flags_initialize( iop, flags );
 
   return fd;
