Blame src/output/mdso_create_output.c

3b42f9
/****************************************************************/
3b42f9
/*  mdso: midipix dso scavenger                                 */
3b42f9
/*  Copyright (C) 2015  Z. Gilboa                               */
3b42f9
/*  Released under GPLv2 and GPLv3; see COPYING.MDSO.           */
3b42f9
/****************************************************************/
3b42f9
3b42f9
#include <stdint.h>
3b42f9
#include <stdlib.h>
3b42f9
#include <stdio.h>
3b42f9
#include <stddef.h>
3b42f9
#include <unistd.h>
3b42f9
#include <fcntl.h>
3b42f9
3b42f9
#include <mdso/mdso.h>
3b42f9
#include "mdso_driver_impl.h"
3b42f9
3b42f9
FILE * mdso_create_output(
3b42f9
	const struct mdso_driver_ctx *	dctx,
3b42f9
	const char *			asmname)
3b42f9
{
3b42f9
	struct mdso_driver_ctx_impl *	ictx;
3b42f9
	uintptr_t			addr;
3b42f9
	int				fdout;
3b42f9
3b42f9
	if (!dctx->cctx->dstdir)
3b42f9
		return stdout;
3b42f9
3b42f9
	addr = (uintptr_t)dctx - offsetof(struct mdso_driver_ctx_impl,ctx);
3b42f9
	ictx = (struct mdso_driver_ctx_impl *)addr;
3b42f9
3b42f9
	if ((fdout = openat(ictx->fddst,asmname,
3b42f9
                        O_CREAT|O_TRUNC|O_WRONLY|O_NOCTTY|O_NOFOLLOW,
3b42f9
                        S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0)
3b42f9
		return 0;
3b42f9
3b42f9
	return fdopen(fdout,"w");
3b42f9
}