testcases/highfd.c
/* changes the given filedescriptor to be the highest possible */
changes the given filedescriptor to be the highest possible
changes the given filedescriptor to be the highest possible
int high_fd(int fd)
{
	struct rlimit lim, hard_lim;
	int newfd, i;
	getrlimit(RLIMIT_NOFILE, &lim);
	hard_lim.rlim_cur = hard_lim.rlim_max = lim.rlim_max;
	setrlimit(RLIMIT_NOFILE, &hard_lim);
	for (i=lim.rlim_max-1; fd < i; i--)
		if ( (newfd = fcntl(fd, F_DUPFD, i)) > -1)
		{
			close(fd);
			fd = newfd;
			if (lim.rlim_cur > fd)
				lim.rlim_cur = fd;
			break;
		}
	setrlimit(RLIMIT_NOFILE, &lim);
	return fd;
}
int high_fd ( int fd ) { struct rlimit lim , hard_lim ; int newfd , i ; getrlimit ( RLIMIT_NOFILE , & lim ) ; hard_lim . rlim_cur = hard_lim . rlim_max = lim . rlim_max ; setrlimit ( RLIMIT_NOFILE , & hard_lim ) ; for ( i = lim . rlim_max - 1 ; fd < i ; i -- ) if ( ( newfd = fcntl ( fd , F_DUPFD , i ) ) > -1 ) { close ( fd ) ; fd = newfd ; if ( lim . rlim_cur > fd ) lim . rlim_cur = fd ; break ; } setrlimit ( RLIMIT_NOFILE , & lim ) ; return fd ; }
changes the given filedescriptor to be the highest possible
changes the given filedescriptor to be the highest possible