diff options
Diffstat (limited to 'fd.c')
-rw-r--r-- | fd.c | 30 |
1 files changed, 17 insertions, 13 deletions
@@ -37,19 +37,6 @@ fd_alloc() return 0; } -void -fd_close(struct fd *fd) -{ - if(fd->type == FD_CLOSED || fd->count <= 0) - panic("fd_close"); - fd->count -= 1; - if(fd->count == 0){ - if(fd->type == FD_PIPE) - pipe_close(fd->pipe, fd->writeable); - fd->type = FD_CLOSED; - } -} - /* * addr is a kernel address, pointing into some process's p->mem. */ @@ -78,3 +65,20 @@ fd_read(struct fd *fd, char *addr, int n) return -1; } } + +void +fd_close(struct fd *fd) +{ + if(fd->count < 1 || fd->type == FD_CLOSED) + panic("fd_close"); + fd->count -= 1; + + if(fd->count == 0){ + if(fd->type == FD_PIPE){ + pipe_close(fd->pipe, fd->writeable); + } else { + panic("fd_close"); + } + fd->type = FD_CLOSED; + } +} |