summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_descrip.c
diff options
context:
space:
mode:
authorpjd <pjd@FreeBSD.org>2012-06-14 15:37:15 +0000
committerpjd <pjd@FreeBSD.org>2012-06-14 15:37:15 +0000
commitf84f6132c816f638e7839c37cfa905434b0dab08 (patch)
tree6ac4e28bcd0feba16068e5fe2326dce7f4f4e2c5 /sys/kern/kern_descrip.c
parent4a9c37500e595195522b7382715df72b5dd15669 (diff)
downloadFreeBSD-src-f84f6132c816f638e7839c37cfa905434b0dab08.zip
FreeBSD-src-f84f6132c816f638e7839c37cfa905434b0dab08.tar.gz
Simplify the code by making more use of the fdtofp() function.
MFC after: 1 month
Diffstat (limited to 'sys/kern/kern_descrip.c')
-rw-r--r--sys/kern/kern_descrip.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index e2fbedf..4a692a6 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -679,8 +679,7 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg)
vfslocked = 0;
/* Check for race with close */
FILEDESC_SLOCK(fdp);
- if (fd < 0 || fd >= fdp->fd_nfiles ||
- fp != fdp->fd_ofiles[fd]) {
+ if (fdtofp(fd, fdp) != fp) {
FILEDESC_SUNLOCK(fdp);
flp->l_whence = SEEK_SET;
flp->l_start = 0;
@@ -822,7 +821,7 @@ do_dup(struct thread *td, int flags, int old, int new,
return (flags & DUP_FCNTL ? EINVAL : EBADF);
FILEDESC_XLOCK(fdp);
- if (old >= fdp->fd_nfiles || fdp->fd_ofiles[old] == NULL) {
+ if (fdtofp(old, fdp) == NULL) {
FILEDESC_XUNLOCK(fdp);
return (EBADF);
}
@@ -1201,8 +1200,7 @@ kern_close(td, fd)
AUDIT_SYSCLOSE(td, fd);
FILEDESC_XLOCK(fdp);
- if (fd < 0 || fd >= fdp->fd_nfiles ||
- (fp = fdp->fd_ofiles[fd]) == NULL) {
+ if ((fp = fdtofp(fd, fdp)) == NULL) {
FILEDESC_XUNLOCK(fdp);
return (EBADF);
}
@@ -2596,8 +2594,7 @@ dupfdopen(struct thread *td, struct filedesc *fdp, int dfd, int mode, int opener
* closed, then reject.
*/
FILEDESC_XLOCK(fdp);
- if (dfd < 0 || dfd >= fdp->fd_nfiles ||
- (fp = fdp->fd_ofiles[dfd]) == NULL) {
+ if ((fp = fdtofp(dfd, fdp)) == NULL) {
FILEDESC_XUNLOCK(fdp);
return (EBADF);
}
OpenPOWER on IntegriCloud