#include "fdset.h"

/* Copy the <from> fdset over the <to> fdset. */
void fdset_copy(fd_set *from, fd_set *to)
{
	memcpy(to, from, sizeof(fd_set));
}

/* Find the highest-numbered file descriptor that is set in <x>
   and return it. This is done without any knowledge of the internals
   of the fd_set, so if your FD_ISSET is slow, then this will be slow. */
int fdset_max(fd_set x)
{
	int fd, max = 0;

	for (fd = 0; fd < NFDBITS; fd++)
	{
		if (FD_ISSET(fd, &x))
			max = fd;
	}
	return max;
}
