[Libsysio-commit] HEAD: libsysio/dev/stdfd stdfd.c
Brought to you by:
lward
From: Lee W. <lw...@us...> - 2004-09-21 17:37:12
|
Update of /cvsroot/libsysio/libsysio/dev/stdfd In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8982/dev/stdfd Modified Files: stdfd.c Log Message: Michael Levenhagen points out that the stdfd device does not support fcntl. We now support F_SETFL and F_GETFL on this device. Index: stdfd.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/dev/stdfd/stdfd.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -w -b -B -p -r1.11 -r1.12 --- stdfd.c 21 Sep 2004 16:18:13 -0000 1.11 +++ stdfd.c 21 Sep 2004 17:36:57 -0000 1.12 @@ -46,8 +46,10 @@ #endif #include <errno.h> +#include <stdarg.h> #include <sys/syscall.h> #include <unistd.h> +#include <fcntl.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/queue.h> @@ -151,10 +153,13 @@ stdfd_read_simple(void *buf, _SYSIO_OFF_T off __IS_UNUSED, struct inode *ino) { - int fd = SYSIO_MINOR_DEV(ino->i_stbuf.st_rdev); + int cc; - return doread(fd, buf, nbytes); + cc = doread(fd, buf, nbytes); + if (cc < 0) + cc = -errno; + return cc; } static int @@ -171,8 +176,12 @@ stdfd_write_simple(const void *buf, struct inode *ino) { int fd = SYSIO_MINOR_DEV(ino->i_stbuf.st_rdev); + int cc; - return dowrite(fd, buf, nbytes); + cc = dowrite(fd, buf, nbytes); + if (cc < 0) + cc = -errno; + return cc; } static int @@ -198,14 +207,34 @@ stdfd_iodone(struct ioctx *iocp __IS_UNU } static int -stdfd_fcntl(struct inode *ino __IS_UNUSED, - int cmd __IS_UNUSED, - va_list ap __IS_UNUSED, +stdfd_fcntl(struct inode *ino, + int cmd, + va_list ap, int *rtn) { + int err; + int fd = SYSIO_MINOR_DEV(ino->i_stbuf.st_rdev); + long arg; + err = 0; + switch (cmd) { + case F_GETFL: + *rtn = syscall(SYS_fcntl, fd, cmd); + if (*rtn == -1) + err = -errno; + break; + case F_SETFL: + arg = va_arg(ap, long); + *rtn = syscall(SYS_fcntl, fd, cmd, arg); + if (*rtn == -1) + err = -errno; + va_end(ap); + break; + default: *rtn = -1; - return -EINVAL; + err = -EINVAL; + } + return err; } static int |