aboutsummaryrefslogtreecommitdiff
path: root/apps/nc/compat/accept4.c
blob: dca42e935ebb3d4f03cc29fe32472c19ff6cb4db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <sys/socket.h>
#include <fcntl.h>

int
accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags)
{
	int rets = accept(s, addr, addrlen);
	if (rets == -1)
		return rets;

	if (flags & SOCK_CLOEXEC) {
		flags = fcntl(rets, F_GETFD);
		fcntl(rets, F_SETFD, flags | FD_CLOEXEC);
	}

	return rets;
}