From ca90c6c1db3881ce5a44e06610a29a128e5455f2 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Wed, 13 Sep 2017 14:00:50 +0200 Subject: libio: Add rtems_libio_iop_flags_initialize() Update #3132. --- cpukit/libcsupport/include/rtems/libio_.h | 18 ++++++++++++++++++ cpukit/libcsupport/src/fcntl.c | 15 +++++++++------ cpukit/libcsupport/src/libio.c | 1 - cpukit/libcsupport/src/open.c | 5 ++++- 4 files changed, 31 insertions(+), 8 deletions(-) (limited to 'cpukit/libcsupport') diff --git a/cpukit/libcsupport/include/rtems/libio_.h b/cpukit/libcsupport/include/rtems/libio_.h index ed5cd27c31..0e128032ec 100644 --- a/cpukit/libcsupport/include/rtems/libio_.h +++ b/cpukit/libcsupport/include/rtems/libio_.h @@ -89,6 +89,24 @@ extern rtems_filesystem_mount_table_entry_t rtems_filesystem_null_mt_entry; */ 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; +} + /** * @brief Sets the specified flags in the iop. * diff --git a/cpukit/libcsupport/src/fcntl.c b/cpukit/libcsupport/src/fcntl.c index 0fe734d61c..82052011ec 100644 --- a/cpukit/libcsupport/src/fcntl.c +++ b/cpukit/libcsupport/src/fcntl.c @@ -26,15 +26,14 @@ static int duplicate_iop( rtems_libio_t *iop ) { - int rv = 0; + int rv; + int oflag; + rtems_libio_t *diop; - rtems_libio_t *diop = rtems_libio_allocate(); + 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 ); rtems_filesystem_instance_unlock( &iop->pathinfo ); @@ -46,6 +45,10 @@ static int duplicate_iop( rtems_libio_t *iop ) */ 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 { rtems_libio_free( diop ); diff --git a/cpukit/libcsupport/src/libio.c b/cpukit/libcsupport/src/libio.c index cd3a4420f6..0cc2b98c0b 100644 --- a/cpukit/libcsupport/src/libio.c +++ b/cpukit/libcsupport/src/libio.c @@ -116,7 +116,6 @@ rtems_libio_t *rtems_libio_allocate( void ) iop = rtems_libio_iop_freelist; rtems_libio_iop_freelist = iop->data1; memset( iop, 0, sizeof(*iop) ); - iop->flags = LIBIO_FLAGS_OPEN; } rtems_libio_unlock(); diff --git a/cpukit/libcsupport/src/open.c b/cpukit/libcsupport/src/open.c index 2ee99f1f4c..22773454ba 100644 --- a/cpukit/libcsupport/src/open.c +++ b/cpukit/libcsupport/src/open.c @@ -96,13 +96,16 @@ static int do_open( } } - 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 ); if ( rv != 0 ) { -- cgit v1.2.3