kernel: simplify fdclose()
This commit is contained in:
parent
89acedb9b8
commit
9ebbfae28b
1 changed files with 5 additions and 13 deletions
|
@ -292,28 +292,20 @@ sysopen(va_list list)
|
||||||
void
|
void
|
||||||
fdclose(int fd, int flag)
|
fdclose(int fd, int flag)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
Chan *c;
|
Chan *c;
|
||||||
Fgrp *f = up->fgrp;
|
Fgrp *f = up->fgrp;
|
||||||
|
|
||||||
lock(f);
|
lock(f);
|
||||||
c = f->fd[fd];
|
c = f->fd[fd];
|
||||||
if(c == 0){
|
if(c == nil || (flag != 0 && (c->flag&flag) == 0)){
|
||||||
/* can happen for users with shared fd tables */
|
|
||||||
unlock(f);
|
unlock(f);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(flag){
|
f->fd[fd] = nil;
|
||||||
if(c==0 || !(c->flag&flag)){
|
if(fd == f->maxfd){
|
||||||
unlock(f);
|
while(fd > 0 && f->fd[fd] == nil)
|
||||||
return;
|
f->maxfd = --fd;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
f->fd[fd] = 0;
|
|
||||||
if(fd == f->maxfd)
|
|
||||||
for(i=fd; --i>=0 && f->fd[i]==0; )
|
|
||||||
f->maxfd = i;
|
|
||||||
|
|
||||||
unlock(f);
|
unlock(f);
|
||||||
cclose(c);
|
cclose(c);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue