if ((ret = fd_lock(fd, FD_RDWR)) == OK) {
if ((ret = fd_lock(fd, FD_RDWR, NULL)) == OK) {
int fcntl(int fd, int cmd, ...){	int ret, realfd, flags;	struct flock *flock;	semaphore *plock;	va_list ap;	flags = 0;	if ((ret = fd_lock(fd, FD_RDWR)) == OK) {		va_start(ap, cmd);		switch(cmd) {		case F_DUPFD:			ret = fd_allocate();			fd_basic_dup(va_arg(ap, int), ret);			break;		case F_SETFD:			flags = va_arg(ap, int);		case F_GETFD:     		ret = fd_table[fd]->ops->fcntl(fd_table[fd]->fd,			  fd_table[fd]->flags, cmd, flags | __FD_NONBLOCK);			break;		case F_GETFL:			ret = fd_table[fd]->flags;			break;		case F_SETFL:			flags = va_arg(ap, int);     		if ((ret = fd_table[fd]->ops->fcntl(fd_table[fd]->fd,			  fd_table[fd]->flags, cmd, flags | __FD_NONBLOCK)) == OK) {				fd_table[fd]->flags = flags;			}			break;/*		case F_SETLKW: */			/*			 * Do the same as SETLK but if it fails with EACCES or EAGAIN			 * block the thread and try again later, not implemented yet			 *//*		case F_SETLK: *//*		case F_GETLK: 			flock = va_arg(ap, struct flock*);     		ret = fd_table[fd]->ops->fcntl(fd_table[fd]->fd,			  fd_table[fd]->flags, cmd, flock);			break; */		default:			/* Might want to make va_arg use a union */     		ret = fd_table[fd]->ops->fcntl(fd_table[fd]->fd,			  fd_table[fd]->flags, cmd, va_arg(ap, void*));			break;		}		va_end(ap);		fd_unlock(fd, FD_RDWR);	}	return(ret);}