summaryrefslogtreecommitdiffhomepage
path: root/src/output/mdso_create_output.c
blob: 3ecde61f48e21e5c18178bdfd81849105caf2ff0 (plain)
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
33
34
35
36
37
/****************************************************************/
/*  mdso: midipix dso scavenger                                 */
/*  Copyright (C) 2015  Z. Gilboa                               */
/*  Released under GPLv2 and GPLv3; see COPYING.MDSO.           */
/****************************************************************/

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include <unistd.h>
#include <fcntl.h>

#include <mdso/mdso.h>
#include "mdso_driver_impl.h"

FILE * mdso_create_output(
	const struct mdso_driver_ctx *	dctx,
	const char *			asmname)
{
	struct mdso_driver_ctx_impl *	ictx;
	uintptr_t			addr;
	int				fdout;

	if (!dctx->cctx->dstdir)
		return stdout;

	addr = (uintptr_t)dctx - offsetof(struct mdso_driver_ctx_impl,ctx);
	ictx = (struct mdso_driver_ctx_impl *)addr;

	if ((fdout = openat(ictx->fddst,asmname,
                        O_CREAT|O_TRUNC|O_WRONLY|O_NOCTTY|O_NOFOLLOW,
                        S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0)
		return 0;

	return fdopen(fdout,"w");
}