aboutsummaryrefslogtreecommitdiffstats
path: root/libexec_renumber_fd.c
blob: d9350facda91a269253f31c1c16722dac3795924 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* See LICENSE file for copyright and license details. */
#include "common.h"
#ifndef TEST


int
libexec_renumber_fd(struct libexec_command *cmd, int fd, int old_fd)
{
	if (fd == old_fd) {
		if (!cmd || fd < 0) {
			errno = EINVAL;
			return -1;
		}
		return 0;
	}
	if (libexec_dup(cmd, fd, old_fd))
		return -1;
	if (libexec_close(cmd, old_fd)) {
		cmd->nplumings -= 1;
		if (!cmd->nplumings) {
			free(cmd->plumings);
			cmd->plumings = NULL;
		}
		return -1;
	}
	return 0;
}


#else
LIBEXEC_CONST__ int main(void) {return 0;} /* TODO test */
#endif