static void alt_open_fd(alt_fd* fd, const char* name, int flags, int mode) { int old; old = open (name, flags, mode); if (old >= 0) { fd->dev = alt_fd_list[old].dev; fd->priv = alt_fd_list[old].priv; fd->fd_flags = alt_fd_list[old].fd_flags; alt_release_fd (old); } }
int ALT_CLOSE (int fildes) { alt_fd* fd; int rval; /* * A common error case is that when the file descriptor was created, the call * to open() failed resulting in a negative file descriptor. This is trapped * below so that we don't try and process an invalid file descriptor. */ fd = (fildes < 0) ? NULL : &alt_fd_list[fildes]; if (fd) { /* * If the associated file system/device has a close function, call it so * that any necessary cleanup code can run. */ rval = (fd->dev->close) ? fd->dev->close(fd) : 0; /* Free the file descriptor structure and return. */ alt_release_fd (fildes); if (rval < 0) { ALT_ERRNO = -rval; return -1; } return 0; } else { ALT_ERRNO = EBADFD; return -1; } }