#include "lib.h" #include #include #include #include "sys9.h" int close(int d) { int n; Fdinfo *f; n = -1; f = &_fdinfo[d]; if(d<0 || d>=OPEN_MAX || !(f->flags&FD_ISOPEN)) errno = EBADF; else{ if(f->flags&FD_BUFFERED) f->flags &= ~FD_BUFFERED; n = _CLOSE(d); if(n < 0) _syserrno(); _fdinfo[d].flags = 0; _fdinfo[d].oflags = 0; if(_fdinfo[d].name){ free(_fdinfo[d].name); _fdinfo[d].name = 0; } } return n; }