Blame src/internal/perk_output_impl.h

e2e2c2
/***************************************************************/
e2e2c2
/*  perk: PE Resource Kit                                      */
e2e2c2
/*  Copyright (C) 2015--2016  Z. Gilboa                        */
e2e2c2
/*  Released under GPLv2 and GPLv3; see COPYING.PERK.          */
e2e2c2
/***************************************************************/
e2e2c2
61bf9c
#ifndef PE_OUTPUT_IMPL_H
61bf9c
#define PE_OUTPUT_IMPL_H
61bf9c
fcd204
#include <unistd.h>
7cd8bc
#include <perk/perk.h>
7cd8bc
2b7f36
static inline FILE * pe_output_prolog(
2b7f36
	const struct pe_common_ctx *	cctx,
2b7f36
	FILE *				fout,
2b7f36
	FILE **				ftmp)
7cd8bc
{
7cd8bc
	int fdout;
7cd8bc
7cd8bc
	*ftmp = (FILE *)0;
7cd8bc
7cd8bc
	if (fout)
7cd8bc
		return fout;
7cd8bc
	else if (!cctx)
7cd8bc
		return 0;
76aabf
	else if (cctx->ioctx->fdout < 0)
7cd8bc
		return stdout;
7cd8bc
76aabf
	if ((fdout = dup(cctx->ioctx->fdout)) < 0)
7cd8bc
		return 0;
7cd8bc
7cd8bc
	if ((*ftmp = fdopen(fdout,"a")))
7cd8bc
		return *ftmp;
7cd8bc
7cd8bc
	close(fdout);
7cd8bc
	return 0;
7cd8bc
}
7cd8bc
7cd8bc
static inline int pe_output_epilog(int ret, FILE * f)
7cd8bc
{
7cd8bc
	if (f)
7cd8bc
		fclose(f);
7cd8bc
	return ret;
7cd8bc
}
61bf9c
61bf9c
#endif