Blame src/helper/mdso_create_asm_source.c

3b42f9
/****************************************************************/
3b42f9
/*  mdso: midipix dso scavenger                                 */
3e816c
/*  Copyright (C) 2015--2016  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"
8cb533
#include "mdso_errinfo_impl.h"
3b42f9
b183d1
FILE * mdso_create_asm_source(
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;
b023b7
	FILE *				fout;
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,
8cb533
                        S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0) {
8cb533
		MDSO_SYSTEM_ERROR(dctx);
3b42f9
		return 0;
8cb533
	}
3b42f9
b023b7
	if (!(fout = fdopen(fdout,"w"))) {
b023b7
		close(fdout);
8cb533
		MDSO_SYSTEM_ERROR(dctx);
b023b7
		return 0;
b023b7
	}
b023b7
b023b7
	return fout;
3b42f9
}