summaryrefslogtreecommitdiffstats
path: root/c/src/exec/libcsupport
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>1998-12-10 23:31:54 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>1998-12-10 23:31:54 +0000
commitcca44008d81209e9fa992157637d9de0384e0536 (patch)
treee13728c80e91a8cff28f98ca7d7e6dea2359e05f /c/src/exec/libcsupport
parentRDBG headers files ignored if not configured (diff)
downloadrtems-cca44008d81209e9fa992157637d9de0384e0536.tar.bz2
Merged Eric Norum's select patch that was based on 4.0 and resolved
all conflicts.
Diffstat (limited to 'c/src/exec/libcsupport')
-rw-r--r--c/src/exec/libcsupport/include/rtems/libio.h6
-rw-r--r--c/src/exec/libcsupport/include/rtems/libio_.h1
-rw-r--r--c/src/exec/libcsupport/include/sys/sockio.h5
-rw-r--r--c/src/exec/libcsupport/src/close.c9
-rw-r--r--c/src/exec/libcsupport/src/fchmod.c7
-rw-r--r--c/src/exec/libcsupport/src/fcntl.c8
-rw-r--r--c/src/exec/libcsupport/src/fdatasync.c10
-rw-r--r--c/src/exec/libcsupport/src/fpathconf.c10
-rw-r--r--c/src/exec/libcsupport/src/fsync.c10
-rw-r--r--c/src/exec/libcsupport/src/ftruncate.c8
-rw-r--r--c/src/exec/libcsupport/src/ioctl.c11
-rw-r--r--c/src/exec/libcsupport/src/libio.c157
-rw-r--r--c/src/exec/libcsupport/src/lseek.c11
-rw-r--r--c/src/exec/libcsupport/src/read.c17
-rw-r--r--c/src/exec/libcsupport/src/write.c17
15 files changed, 166 insertions, 121 deletions
diff --git a/c/src/exec/libcsupport/include/rtems/libio.h b/c/src/exec/libcsupport/include/rtems/libio.h
index ee0aaf9b7f..740574f303 100644
--- a/c/src/exec/libcsupport/include/rtems/libio.h
+++ b/c/src/exec/libcsupport/include/rtems/libio.h
@@ -393,12 +393,16 @@ typedef struct {
#define LIBIO_FLAGS_NO_DELAY 0x0001 /* return immediately if no data */
#define LIBIO_FLAGS_READ 0x0002 /* reading */
#define LIBIO_FLAGS_WRITE 0x0004 /* writing */
-#define LIBIO_FLAGS_LINE_BUFFERED 0x0008 /* line buffered io (^h, ^u, etc) */
#define LIBIO_FLAGS_OPEN 0x0100 /* device is open */
#define LIBIO_FLAGS_APPEND 0x0200 /* all writes append */
#define LIBIO_FLAGS_CREATE 0x0400 /* create file */
#define LIBIO_FLAGS_CLOSE_ON_EXEC 0x0800 /* close on process exec() */
+#define LIBIO_FLAGS_HANDLER_SHIFT 12
+#define LIBIO_FLAGS_HANDLER_MASK 0xF000 /* mask for external handler type */
+#define LIBIO_FLAGS_HANDLER_RTEMS 0x0000 /* `traditional' RTEMS I/O */
+#define LIBIO_FLAGS_HANDLER_SOCK 0x1000 /* BSD socket */
+
#define LIBIO_FLAGS_READ_WRITE (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE)
diff --git a/c/src/exec/libcsupport/include/rtems/libio_.h b/c/src/exec/libcsupport/include/rtems/libio_.h
index 33a9e7bda5..d595500430 100644
--- a/c/src/exec/libcsupport/include/rtems/libio_.h
+++ b/c/src/exec/libcsupport/include/rtems/libio_.h
@@ -65,6 +65,7 @@ extern rtems_id rtems_libio_semaphore;
extern unsigned32 rtems_libio_number_iops;
extern rtems_libio_t *rtems_libio_iops;
extern rtems_libio_t *rtems_libio_last_iop;
+extern rtems_libio_t *rtems_libio_iop_freelist;
/*
* External I/O Handlers Table
diff --git a/c/src/exec/libcsupport/include/sys/sockio.h b/c/src/exec/libcsupport/include/sys/sockio.h
index 03ec16e43a..5e54baffe8 100644
--- a/c/src/exec/libcsupport/include/sys/sockio.h
+++ b/c/src/exec/libcsupport/include/sys/sockio.h
@@ -83,11 +83,10 @@
#define SIOCSIFMEDIA _IOWR('i', 55, struct ifreq) /* set net media */
#define SIOCGIFMEDIA _IOWR('i', 56, struct ifmediareq) /* get net media */
-
/*
* RTEMS additions for setting/getting `tap' function on incoming packets.
*/
-#define SIOCSIFTAP _IOW('i', 80, struct ifreq) /* set tap function */
-#define SIOCGIFTAP _IOWR('i', 81, struct ifreq) /* get tap function */
+#define SIOCSIFTAP _IOW('i', 80, struct ifreq) /* set tap function */
+#define SIOCGIFTAP _IOW('i', 81, struct ifreq) /* get tap function */
#endif /* !_SYS_SOCKIO_H_ */
diff --git a/c/src/exec/libcsupport/src/close.c b/c/src/exec/libcsupport/src/close.c
index 94ddb45c90..0583a36b22 100644
--- a/c/src/exec/libcsupport/src/close.c
+++ b/c/src/exec/libcsupport/src/close.c
@@ -22,17 +22,18 @@ int close(
rtems_status_code rc;
int status;
- if ( rtems_file_descriptor_type( fd ) ) {
+ rtems_libio_check_fd(fd);
+ iop = rtems_libio_iop(fd);
+ if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
int (*fp)(int fd);
- fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].close;
+ fp = rtems_libio_handlers[
+ (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].close;
if ( fp == NULL )
set_errno_and_return_minus_one( EBADF );
status = (*fp)( fd );
return status;
}
- iop = rtems_libio_iop(fd);
- rtems_libio_check_fd(fd);
if ( !iop->handlers )
set_errno_and_return_minus_one( EBADF );
diff --git a/c/src/exec/libcsupport/src/fchmod.c b/c/src/exec/libcsupport/src/fchmod.c
index a3ca4507ab..f202a30eb0 100644
--- a/c/src/exec/libcsupport/src/fchmod.c
+++ b/c/src/exec/libcsupport/src/fchmod.c
@@ -27,19 +27,20 @@ int fchmod(
{
rtems_libio_t *iop;
+ rtems_libio_check_fd( fd );
+ iop = rtems_libio_iop( fd );
+
/*
* If this is not a file system based entity, it is an error.
*/
- if ( rtems_file_descriptor_type( fd ) )
+ if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
set_errno_and_return_minus_one( EBADF );
/*
* Now process the fchmod().
*/
- iop = rtems_libio_iop( fd );
- rtems_libio_check_fd( fd );
rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
if ( !iop->handlers->fchmod )
diff --git a/c/src/exec/libcsupport/src/fcntl.c b/c/src/exec/libcsupport/src/fcntl.c
index a538ec1cf9..b327a447ac 100644
--- a/c/src/exec/libcsupport/src/fcntl.c
+++ b/c/src/exec/libcsupport/src/fcntl.c
@@ -32,20 +32,20 @@ int fcntl(
va_start( ap, cmd );
+ rtems_libio_check_fd( fd );
+ iop = rtems_libio_iop( fd );
+
/*
* If this is not a file system based entity, it is an error.
*/
- if ( rtems_file_descriptor_type( fd ) )
+ if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
set_errno_and_return_minus_one( EBADF );
/*
* Now process the fcntl().
*/
- iop = rtems_libio_iop( fd );
- rtems_libio_check_fd( fd );
-
/*
* This switch should contain all the cases from POSIX.
*/
diff --git a/c/src/exec/libcsupport/src/fdatasync.c b/c/src/exec/libcsupport/src/fdatasync.c
index 58a4c4e118..91bff3aaba 100644
--- a/c/src/exec/libcsupport/src/fdatasync.c
+++ b/c/src/exec/libcsupport/src/fdatasync.c
@@ -22,22 +22,22 @@ int fdatasync(
{
rtems_libio_t *iop;
+ rtems_libio_check_fd( fd );
+ iop = rtems_libio_iop( fd );
+ rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
+
/*
* If this file descriptor is mapped to an external set of handlers,
* then pass the request on to them.
*/
- if ( rtems_file_descriptor_type( fd ) )
+ if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
set_errno_and_return_minus_one( EBADF );
/*
* Now process the fdatasync().
*/
- iop = rtems_libio_iop( fd );
- rtems_libio_check_fd( fd );
- rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
-
if ( !iop->handlers->fdatasync )
set_errno_and_return_minus_one( ENOTSUP );
diff --git a/c/src/exec/libcsupport/src/fpathconf.c b/c/src/exec/libcsupport/src/fpathconf.c
index ea2377e15b..f3fb1162d0 100644
--- a/c/src/exec/libcsupport/src/fpathconf.c
+++ b/c/src/exec/libcsupport/src/fpathconf.c
@@ -26,23 +26,23 @@ long fpathconf(
rtems_libio_t *iop;
rtems_filesystem_limits_and_options_t *the_limits;
+ rtems_libio_check_fd(fd);
+ iop = rtems_libio_iop(fd);
+ rtems_libio_check_permissions(iop, LIBIO_FLAGS_READ);
+
/*
* If this file descriptor is mapped to an external set of handlers,
* then it is an error since fpathconf() is not included in the
* set.
*/
- if ( rtems_file_descriptor_type( fd ) )
+ if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
set_errno_and_return_minus_one( EBADF );
/*
* Now process the information request.
*/
- iop = rtems_libio_iop(fd);
- rtems_libio_check_fd(fd);
- rtems_libio_check_permissions(iop, LIBIO_FLAGS_READ);
-
the_limits = &iop->pathinfo.mt_entry->pathconf_limits_and_options;
switch ( name ) {
diff --git a/c/src/exec/libcsupport/src/fsync.c b/c/src/exec/libcsupport/src/fsync.c
index a5ed1e99e7..b77c77312c 100644
--- a/c/src/exec/libcsupport/src/fsync.c
+++ b/c/src/exec/libcsupport/src/fsync.c
@@ -22,22 +22,22 @@ int fsync(
{
rtems_libio_t *iop;
+ rtems_libio_check_fd( fd );
+ iop = rtems_libio_iop( fd );
+ rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
+
/*
* If this file descriptor is mapped to an external set of handlers,
* then pass the request on to them.
*/
- if ( rtems_file_descriptor_type( fd ) )
+ if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
set_errno_and_return_minus_one( EBADF );
/*
* Now process the fsync().
*/
- iop = rtems_libio_iop( fd );
- rtems_libio_check_fd( fd );
- rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
-
if ( !iop->handlers->fsync )
set_errno_and_return_minus_one( ENOTSUP );
diff --git a/c/src/exec/libcsupport/src/ftruncate.c b/c/src/exec/libcsupport/src/ftruncate.c
index 7fb2286531..5bcb2ea5d8 100644
--- a/c/src/exec/libcsupport/src/ftruncate.c
+++ b/c/src/exec/libcsupport/src/ftruncate.c
@@ -25,19 +25,20 @@ int ftruncate(
rtems_libio_t *iop;
rtems_filesystem_location_info_t loc;
+ rtems_libio_check_fd( fd );
+ iop = rtems_libio_iop( fd );
+
/*
* If this is not a file system based entity, it is an error.
*/
- if ( rtems_file_descriptor_type( fd ) )
+ if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
set_errno_and_return_minus_one( EBADF );
/*
* Now process the ftruncate() request.
*/
- iop = rtems_libio_iop( fd );
-
/*
* Make sure we are not working on a directory
*/
@@ -49,7 +50,6 @@ int ftruncate(
if ( (*loc.ops->node_type)( &loc ) == RTEMS_FILESYSTEM_DIRECTORY )
set_errno_and_return_minus_one( EISDIR );
- rtems_libio_check_fd( fd );
rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
if ( !iop->handlers->ftruncate )
diff --git a/c/src/exec/libcsupport/src/ioctl.c b/c/src/exec/libcsupport/src/ioctl.c
index 0aaf0379ae..9284c7f9dc 100644
--- a/c/src/exec/libcsupport/src/ioctl.c
+++ b/c/src/exec/libcsupport/src/ioctl.c
@@ -26,15 +26,19 @@ int ioctl(
rtems_status_code rc;
rtems_libio_t *iop;
+ rtems_libio_check_fd( fd );
+ iop = rtems_libio_iop( fd );
+
/*
* If this file descriptor is mapped to an external set of handlers,
* then pass the request on to them.
*/
- if ( rtems_file_descriptor_type( fd ) ) {
+ if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
rtems_libio_ioctl_t fp;
- fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].ioctl;
+ fp = rtems_libio_handlers[
+ (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].ioctl;
if ( fp == NULL )
set_errno_and_return_minus_one( EBADF );
@@ -45,9 +49,6 @@ int ioctl(
* Now process the ioctl().
*/
- iop = rtems_libio_iop( fd );
- rtems_libio_check_fd( fd );
-
if ( !iop->handlers->ioctl )
set_errno_and_return_minus_one( ENOTSUP );
diff --git a/c/src/exec/libcsupport/src/libio.c b/c/src/exec/libcsupport/src/libio.c
index e63a4626d4..88aea9b62f 100644
--- a/c/src/exec/libcsupport/src/libio.c
+++ b/c/src/exec/libcsupport/src/libio.c
@@ -3,9 +3,6 @@
* table of integer style file descriptors used by the low level
* POSIX system calls like open(), read, fstat(), etc.
*
- * This provides the foundation for POSIX compliant IO system calls
- * for RTEMS.
- *
* COPYRIGHT (c) 1989-1998.
* On-Line Applications Research Corporation (OAR).
* Copyright assigned to U.S. Government, 1994.
@@ -18,18 +15,56 @@
*/
#include "libio_.h" /* libio_.h pulls in rtems */
+#include <rtems.h>
+#include <rtems/assoc.h> /* assoc.h not included by rtems.h */
+
+#include <stdio.h> /* O_RDONLY, et.al. */
+#include <fcntl.h> /* O_RDONLY, et.al. */
+#include <assert.h>
+#include <errno.h>
+
+#if ! defined(O_NDELAY)
+# if defined(solaris2)
+# define O_NDELAY O_NONBLOCK
+# elif defined(RTEMS_NEWLIB)
+# define O_NDELAY _FNBIO
+# endif
+#endif
+
+
+#include <errno.h>
+#include <string.h> /* strcmp */
+#include <unistd.h>
+#include <stdlib.h> /* calloc() */
+
+#include "libio.h" /* libio.h not pulled in by rtems */
+
+/*
+ * File descriptor Table Information
+ */
+
+extern unsigned32 rtems_libio_number_iops;
+rtems_id rtems_libio_semaphore;
+rtems_libio_t *rtems_libio_iops;
+rtems_libio_t *rtems_libio_last_iop;
+rtems_libio_t *rtems_libio_iop_freelist;
/*
- * Global variables used to manage the File Descriptor Table.
- * IOP = IO Pointer.
+ * External I/O Handlers Table
+ *
+ * Space for all possible handlers is preallocated
+ * to speed up dispatch to external handlers.
*/
-rtems_id rtems_libio_semaphore;
-rtems_libio_t *rtems_libio_iops;
-rtems_libio_t *rtems_libio_last_iop;
rtems_libio_handler_t rtems_libio_handlers[15];
/*
+ * Default mode for all files.
+ */
+
+mode_t rtems_filesystem_umask;
+
+/*
* rtems_register_libio_handler
*
* This function registers an external IO handler set. This lets
@@ -44,8 +79,7 @@ void rtems_register_libio_handler(
const rtems_libio_handler_t *handler
)
{
- int handler_index = rtems_file_descriptor_type_index( handler_flag );
-
+ int handler_index = (handler_flag >> LIBIO_FLAGS_HANDLER_SHIFT) - 1;
if ((handler_index < 0) || (handler_index >= 15))
rtems_fatal_error_occurred( RTEMS_INVALID_NUMBER );
@@ -61,21 +95,22 @@ void rtems_register_libio_handler(
void rtems_libio_init( void )
{
- rtems_status_code rc;
-
- /*
- * Allocate memory for the IOP Table
- */
-
- if ( rtems_libio_number_iops > 0 ) {
- rtems_libio_iops =
- (rtems_libio_t *) calloc(rtems_libio_number_iops, sizeof(rtems_libio_t));
-
- if (rtems_libio_iops == NULL)
- rtems_fatal_error_occurred( RTEMS_NO_MEMORY );
-
- rtems_libio_last_iop = rtems_libio_iops + (rtems_libio_number_iops - 1);
- }
+ rtems_status_code rc;
+ int i;
+ rtems_libio_t *iop;
+
+ if (rtems_libio_number_iops > 0)
+ {
+ rtems_libio_iops = (rtems_libio_t *) calloc(rtems_libio_number_iops,
+ sizeof(rtems_libio_t));
+ if (rtems_libio_iops == NULL)
+ rtems_fatal_error_occurred(RTEMS_NO_MEMORY);
+
+ iop = rtems_libio_iop_freelist = rtems_libio_iops;
+ for (i = 0 ; i < (rtems_libio_number_iops - 1) ; i++, iop++)
+ iop->data1 = iop + 1;
+ iop->data1 = NULL;
+ }
/*
* Create the binary semaphore used to provide mutual exclusion
@@ -157,24 +192,21 @@ rtems_libio_t *rtems_libio_allocate( void )
rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT );
- for (iop = rtems_libio_iops; iop <= rtems_libio_last_iop; iop++)
- if ((iop->flags & LIBIO_FLAGS_OPEN) == 0) {
- /*
- * Got an IOP -- create a semaphore for it.
- */
-
- rc = rtems_semaphore_create(
- RTEMS_LIBIO_IOP_SEM(iop - rtems_libio_iops),
- 1,
- RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY,
- RTEMS_NO_PRIORITY,
- &iop->sem
- );
- if ( rc != RTEMS_SUCCESSFUL )
- goto failed;
-
- iop->flags = LIBIO_FLAGS_OPEN;
- goto done;
+ if (rtems_libio_iop_freelist) {
+ iop = rtems_libio_iop_freelist;
+ rc = rtems_semaphore_create(
+ RTEMS_LIBIO_IOP_SEM(iop - rtems_libio_iops),
+ 1,
+ RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY,
+ RTEMS_NO_PRIORITY,
+ &iop->sem
+ );
+ if (rc != RTEMS_SUCCESSFUL)
+ goto failed;
+ rtems_libio_iop_freelist = iop->data1;
+ iop->data1 = 0;
+ iop->flags = LIBIO_FLAGS_OPEN;
+ goto done;
}
failed:
@@ -198,19 +230,20 @@ void rtems_libio_free(
{
rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT );
- if (iop->sem)
- rtems_semaphore_delete(iop->sem);
+ if (iop->sem)
+ rtems_semaphore_delete(iop->sem);
- (void) memset(iop, 0, sizeof(*iop));
+ iop->data1 = rtems_libio_iop_freelist;
+ rtems_libio_iop_freelist = iop;
- rtems_semaphore_release( rtems_libio_semaphore );
+ rtems_semaphore_release(rtems_libio_semaphore);
}
/*
* rtems_libio_is_open_files_in_fs
*
* This routine scans the entire file descriptor table to determine if the
- * are any active file descriptors that refer to the atleast one node in the
+ * are any active file descriptors that refer to the at least one node in the
* file system that we are trying to dismount.
*
* If there is at least one node in the file system referenced by the mount
@@ -225,19 +258,19 @@ int rtems_libio_is_open_files_in_fs(
int result = 0;
rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT );
-
+
/*
* Look for any active file descriptor entry.
- */
-
+ */
+
for ( iop=rtems_libio_iops ; iop <= rtems_libio_last_iop ; iop++ ) {
-
+
if ((iop->flags & LIBIO_FLAGS_OPEN) != 0) {
-
+
/*
* Check if this node is under the file system that we
* are trying to dismount.
- */
+ */
if ( iop->pathinfo.mt_entry == fs_mt_entry ) {
result = 1;
@@ -247,7 +280,7 @@ int rtems_libio_is_open_files_in_fs(
}
rtems_semaphore_release( rtems_libio_semaphore );
-
+
return result;
}
@@ -256,7 +289,7 @@ int rtems_libio_is_open_files_in_fs(
*
* This routine scans the entire file descriptor table to determine if the
* given file refers to an active file descriptor.
- *
+ *
* If the given file is open a 1 is returned, otherwise a 0 is returned.
*/
@@ -265,22 +298,22 @@ int rtems_libio_is_file_open(
)
{
rtems_libio_t *iop;
- int result=0;
+ int result=0;
rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT );
/*
* Look for any active file descriptor entry.
*/
-
+
for ( iop=rtems_libio_iops ; iop <= rtems_libio_last_iop ; iop++ ) {
-
+
if ((iop->flags & LIBIO_FLAGS_OPEN) != 0) {
-
+
/*
* Check if this node is under the file system that we
* are trying to dismount.
- */
+ */
if ( iop->pathinfo.node_access == node_access ) {
result = 1;
@@ -293,3 +326,5 @@ int rtems_libio_is_file_open(
return result;
}
+
+
diff --git a/c/src/exec/libcsupport/src/lseek.c b/c/src/exec/libcsupport/src/lseek.c
index 514f8cd912..cd8046356f 100644
--- a/c/src/exec/libcsupport/src/lseek.c
+++ b/c/src/exec/libcsupport/src/lseek.c
@@ -24,15 +24,19 @@ off_t lseek(
{
rtems_libio_t *iop;
+ rtems_libio_check_fd( fd );
+ iop = rtems_libio_iop( fd );
+
/*
* If this file descriptor is mapped to an external set of handlers,
* then pass the request on to them.
*/
- if ( rtems_file_descriptor_type( fd ) ) {
+ if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
rtems_libio_lseek_t fp;
- fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].lseek;
+ fp = rtems_libio_handlers[
+ (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].lseek;
if ( fp == NULL )
set_errno_and_return_minus_one( EBADF );
@@ -43,9 +47,6 @@ off_t lseek(
* Now process the lseek().
*/
- iop = rtems_libio_iop( fd );
- rtems_libio_check_fd( fd );
-
switch ( whence ) {
case SEEK_SET:
iop->offset = offset;
diff --git a/c/src/exec/libcsupport/src/read.c b/c/src/exec/libcsupport/src/read.c
index 150fe675ab..1ed6a0bd00 100644
--- a/c/src/exec/libcsupport/src/read.c
+++ b/c/src/exec/libcsupport/src/read.c
@@ -26,15 +26,22 @@ int read(
int rc; /* XXX change to a size_t when prototype is fixed */
rtems_libio_t *iop;
+ rtems_libio_check_fd( fd );
+ iop = rtems_libio_iop( fd );
+ rtems_libio_check_buffer( buffer );
+ rtems_libio_check_count( count );
+ rtems_libio_check_permissions( iop, LIBIO_FLAGS_READ );
+
/*
* If this file descriptor is mapped to an external set of handlers,
* then pass the request on to them.
*/
- if ( rtems_file_descriptor_type( fd ) ) {
+ if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
rtems_libio_read_t fp;
- fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].read;
+ fp = rtems_libio_handlers[
+ (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].read;
if ( fp == NULL )
set_errno_and_return_minus_one( EBADF );
@@ -45,12 +52,6 @@ int read(
* Now process the read().
*/
- iop = rtems_libio_iop( fd );
- rtems_libio_check_fd( fd );
- rtems_libio_check_buffer( buffer );
- rtems_libio_check_count( count );
- rtems_libio_check_permissions( iop, LIBIO_FLAGS_READ );
-
if ( !iop->handlers->read )
set_errno_and_return_minus_one( ENOTSUP );
diff --git a/c/src/exec/libcsupport/src/write.c b/c/src/exec/libcsupport/src/write.c
index 7e0953bb90..3de21f0d0f 100644
--- a/c/src/exec/libcsupport/src/write.c
+++ b/c/src/exec/libcsupport/src/write.c
@@ -34,15 +34,22 @@ int write( /* XXX this should return a ssize_t */
rtems_status_code rc;
rtems_libio_t *iop;
+ rtems_libio_check_fd( fd );
+ iop = rtems_libio_iop( fd );
+ rtems_libio_check_buffer( buffer );
+ rtems_libio_check_count( count );
+ rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
+
/*
* If this file descriptor is mapped to an external set of handlers,
* then pass the request on to them.
*/
- if ( rtems_file_descriptor_type( fd ) ) {
+ if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
rtems_libio_write_t fp;
- fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].write;
+ fp = rtems_libio_handlers[
+ (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].write;
if ( fp == NULL )
set_errno_and_return_minus_one( EBADF );
@@ -53,12 +60,6 @@ int write( /* XXX this should return a ssize_t */
* Now process the write() request.
*/
- iop = rtems_libio_iop( fd );
- rtems_libio_check_fd( fd );
- rtems_libio_check_buffer( buffer );
- rtems_libio_check_count( count );
- rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
-
if ( !iop->handlers->write )
set_errno_and_return_minus_one( ENOTSUP );