diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 1999-03-19 21:51:58 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 1999-03-19 21:51:58 +0000 |
commit | af0200363e8d0a69648bd78fd5ee2d0ee5f40624 (patch) | |
tree | 5134c59a5e4afdf27dec4559ad764a099a66c5e1 /cpukit/libcsupport | |
parent | b64b1ed387bb9fa18e33bc9d7c24aa7fcce38da6 (diff) |
Patch from Eric Norum <eric@skatter.usask.ca> that adds external
fcntl support and an external fcntl handler for sockets.
Diffstat (limited to 'cpukit/libcsupport')
-rw-r--r-- | cpukit/libcsupport/include/rtems/libio.h | 6 | ||||
-rw-r--r-- | cpukit/libcsupport/src/fcntl.c | 60 |
2 files changed, 42 insertions, 24 deletions
diff --git a/cpukit/libcsupport/include/rtems/libio.h b/cpukit/libcsupport/include/rtems/libio.h index 1cbfef383b..6ded1e361d 100644 --- a/cpukit/libcsupport/include/rtems/libio.h +++ b/cpukit/libcsupport/include/rtems/libio.h @@ -115,6 +115,11 @@ typedef int (*rtems_filesystem_fdatasync_t)( rtems_libio_t *iop ); +typedef int (*rtems_filesystem_fcntl_t)( + int cmd, + rtems_libio_t *iop +); + typedef struct { rtems_filesystem_open_t open; rtems_filesystem_close_t close; @@ -128,6 +133,7 @@ typedef struct { rtems_filesystem_fpathconf_t fpathconf; rtems_filesystem_fsync_t fsync; rtems_filesystem_fdatasync_t fdatasync; + rtems_filesystem_fcntl_t fcntl; } rtems_filesystem_file_handlers_r; /* diff --git a/cpukit/libcsupport/src/fcntl.c b/cpukit/libcsupport/src/fcntl.c index 381df45f26..3a65a74574 100644 --- a/cpukit/libcsupport/src/fcntl.c +++ b/cpukit/libcsupport/src/fcntl.c @@ -30,6 +30,7 @@ int fcntl( rtems_libio_t *diop; int fd2; int flags; + int ret = 0; va_start( ap, cmd ); @@ -53,8 +54,10 @@ int fcntl( else { /* allocate a file control block */ diop = rtems_libio_allocate(); - if ( diop == 0 ) - return -1; + if ( diop == 0 ) { + ret = -1; + break; + } } diop->handlers = iop->handlers; @@ -62,12 +65,11 @@ int fcntl( diop->flags = iop->flags; diop->pathinfo = iop->pathinfo; - return 0; + break; case F_GETFD: /* get f_flags */ - if ( iop->flags & LIBIO_FLAGS_CLOSE_ON_EXEC ) - return 1; - return 0; + ret = ((iop->flags & LIBIO_FLAGS_CLOSE_ON_EXEC) != 0); + break; case F_SETFD: /* set f_flags */ /* @@ -82,46 +84,56 @@ int fcntl( iop->flags |= LIBIO_FLAGS_CLOSE_ON_EXEC; else iop->flags &= ~LIBIO_FLAGS_CLOSE_ON_EXEC; - return 0; + break; case F_GETFL: /* more flags (cloexec) */ - return rtems_libio_to_fcntl_flags( iop->flags ); + ret = rtems_libio_to_fcntl_flags( iop->flags ); case F_SETFL: flags = rtems_libio_fcntl_flags( va_arg( ap, int ) ); /* - * XXX Double check this in the POSIX spec. According to the Linux - * XXX man page, only these flags can be added. - */ - - flags = (iop->flags & ~(O_APPEND|O_NONBLOCK)) | - (flags & (O_APPEND|O_NONBLOCK)); - - /* * XXX If we are turning on append, should we seek to the end? */ - iop->flags = flags; - return 0; + iop->flags = (iop->flags & ~(O_APPEND | O_NONBLOCK)) | + (flags & (O_APPEND | O_NONBLOCK)); + break; case F_GETLK: - return -1; + errno = ENOTSUP; + ret = -1; + break; case F_SETLK: - return -1; + errno = ENOTSUP; + ret = -1; + break; case F_SETLKW: - return -1; + errno = ENOTSUP; + ret = -1; + break; case F_SETOWN: /* for sockets. */ - return -1; + errno = ENOTSUP; + ret = -1; + break; case F_GETOWN: /* for sockets. */ - return -1; + errno = ENOTSUP; + ret = -1; + break; default: break; } - return -1; + if ((ret >= 0) && iop->handlers->fcntl) { + int err = (*iop->handlers->fcntl)( cmd, iop ); + if (err) { + errno = err; + ret = -1; + } + } + return ret; } |