summaryrefslogtreecommitdiff
path: root/minix/lib/libc/sys/m_closefrom.c
blob: 14db9f80fcbfd9e905b7fe2dcf66cbc779058873 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <sys/cdefs.h>
#include "namespace.h"
#include <lib.h>
#include <stdlib.h>
#include <unistd.h>

int closefrom(int fd)
{
	int f, ok = 0, e = 0;
	for(f = fd; f < OPEN_MAX; f++) {
		if(close(f) >= 0)
			ok = 1;
		else
			e = errno;
	}

	if(ok)
		return 0;

	/* all failed - return last valid error */
	errno = e;
	return -1;
}