diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2014-05-26 22:47:34 +0200 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2014-05-26 22:47:34 +0200 |
commit | 9ebbfae28b3be0ffcc2122024441cac2f0025c09 (patch) | |
tree | 2fd1884b76e6564eac3ff40487ef780f290f1bc4 | |
parent | 89acedb9b8c8cf88f0a706184852adb7e8767b14 (diff) |
kernel: simplify fdclose()
-rw-r--r-- | sys/src/9/port/sysfile.c | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/sys/src/9/port/sysfile.c b/sys/src/9/port/sysfile.c index 9dfeb5371..a354d6e96 100644 --- a/sys/src/9/port/sysfile.c +++ b/sys/src/9/port/sysfile.c @@ -292,28 +292,20 @@ sysopen(va_list list) void fdclose(int fd, int flag) { - int i; Chan *c; Fgrp *f = up->fgrp; lock(f); c = f->fd[fd]; - if(c == 0){ - /* can happen for users with shared fd tables */ + if(c == nil || (flag != 0 && (c->flag&flag) == 0)){ unlock(f); return; } - if(flag){ - if(c==0 || !(c->flag&flag)){ - unlock(f); - return; - } + f->fd[fd] = nil; + if(fd == f->maxfd){ + while(fd > 0 && f->fd[fd] == nil) + 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); cclose(c); } |