aboutsummaryrefslogblamecommitdiffstats
path: root/libexec_renumber_fd.c
blob: d9350facda91a269253f31c1c16722dac3795924 (plain) (tree)































                                                                    
/* 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