kernels/linux-2.4.0/fs/fcntl.c
/*
 * locate_fd finds a free file descriptor in the open_fds fdset,
 * expanding the fd arrays if necessary.  The files write lock will be
 * held on exit to ensure that the fd can be entered atomically.
 */
locate_fd finds a free file descriptor in the open_fds fdset,
expanding the fd arrays if necessary.  The files write lock will be
held on exit to ensure that the fd can be entered atomically.
locate_fd finds a free file descriptor in the open_fds fdset expanding the fd arrays if necessary . The files write lock will be held on exit to ensure that the fd can be entered atomically .
static int locate_fd(struct files_struct *files, 
			    struct file *file, int orig_start)
{
	unsigned int newfd;
	int error;
	int start;
	write_lock(&files->file_lock);
repeat:
	start = orig_start;
	if (start < files->next_fd)
		start = files->next_fd;
	newfd = start;
	if (start < files->max_fdset) {
		newfd = find_next_zero_bit(files->open_fds->fds_bits,
			files->max_fdset, start);
	}
	error = -EMFILE;
	if (newfd >= current->rlim[RLIMIT_NOFILE].rlim_cur)
		goto out;
	error = expand_files(files, newfd);
	if (error < 0)
		goto out;
	if (error)
		goto repeat;
	if (start <= files->next_fd)
		files->next_fd = newfd + 1;
	error = newfd;
out:
	return error;
}
static int locate_fd ( struct files_struct * files , struct file * file , int orig_start ) { unsigned int newfd ; int error ; int start ; write_lock ( & files -> file_lock ) ; repeat : start = orig_start ; if ( start < files -> next_fd ) start = files -> next_fd ; newfd = start ; if ( start < files -> max_fdset ) { newfd = find_next_zero_bit ( files -> open_fds -> fds_bits , files -> max_fdset , start ) ; } error = - EMFILE ; if ( newfd >= current -> rlim [ RLIMIT_NOFILE ] . rlim_cur ) goto out ; error = expand_files ( files , newfd ) ; if ( error < 0 ) goto out ; if ( error ) goto repeat ; if ( start <= files -> next_fd ) files -> next_fd = newfd + 1 ; error = newfd ; out : return error ; }
locate_fd finds a free file descriptor in the open_fds fdset,
 expanding the fd arrays if necessary.
locate_fd finds a free file descriptor in the open_fds fdset expanding the fd arrays if necessary .
/*
	 * Someone might have closed fd's in the range
	 * orig_start..files->next_fd
	 */ /*
	 * If we needed to expand the fs array we
	 * might have blocked - try again.
	 */