155714Skris/*-
255714Skris * Copyright (c) 2012 The FreeBSD Foundation
355714Skris * All rights reserved.
455714Skris *
555714Skris * This software was developed by Pawel Jakub Dawidek under sponsorship from
655714Skris * the FreeBSD Foundation.
755714Skris *
855714Skris * Redistribution and use in source and binary forms, with or without
955714Skris * modification, are permitted provided that the following conditions
1055714Skris * are met:
1155714Skris * 1. Redistributions of source code must retain the above copyright
1255714Skris *    notice, this list of conditions and the following disclaimer.
1355714Skris * 2. Redistributions in binary form must reproduce the above copyright
1455714Skris *    notice, this list of conditions and the following disclaimer in the
1555714Skris *    documentation and/or other materials provided with the distribution.
1655714Skris *
1755714Skris * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
1855714Skris * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1955714Skris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2055714Skris * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
2155714Skris * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2255714Skris * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2355714Skris * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2455714Skris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2555714Skris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2655714Skris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2755714Skris * SUCH DAMAGE.
2855714Skris *
2955714Skris * $P4: //depot/projects/trustedbsd/openbsm/compat/closefrom.h#1 $
3055714Skris */
3155714Skris
3255714Skris#ifndef	_CLOSEFROM_H_
3355714Skris#define	_CLOSEFROM_H_
3455714Skris
3555714Skris#include <unistd.h>
3655714Skris
3755714Skrisstatic void
3855714Skrisclosefrom(int lowfd)
3955714Skris{
4055714Skris	int error, fd, maxfd;
4155714Skris
4255714Skris	error = errno;
4355714Skris
4455714Skris	maxfd = sysconf(_SC_OPEN_MAX);
4555714Skris	if (maxfd < 0)
4655714Skris		maxfd = 16384;
4755714Skris	for (fd = lowfd; fd <= maxfd; fd++)
4855714Skris		(void)close(fd);
4955714Skris
5055714Skris	errno = error;
5155714Skris}
5255714Skris
5355714Skris#endif /* !_CLOSEFROM_H_ */
5455714Skris