summaryrefslogtreecommitdiffhomepage
path: root/src/output/mdso_output_export_symbols.c
blob: eaac2418d26421f65dc43e3b2d3d4229a445ed1b (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
38
39
40
41
42
43
44
45
46
47
48
49
/****************************************************************/
/*  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 <string.h>
#include <errno.h>

#include <mdso/mdso.h>
#include <mdso/mdso_output.h>

static int pretty_header(const struct mdso_common_ctx * cctx, FILE * fout)
{
	return (cctx->fmtflags & MDSO_PRETTY_YAML)
		? fputs("exports:\n",fout)
		: 0;
}

static int pretty_export_item(const struct mdso_common_ctx * cctx, const char * name, FILE * fout)
{
	if (cctx->fmtflags & MDSO_PRETTY_YAML)
		return fprintf(fout,"- %s\n",name);
	else
		return fprintf(fout,"%s\n",name);
}

int mdso_output_export_symbols(
	const struct mdso_unit_ctx *	uctx,
	const struct mdso_common_ctx *	cctx,
	FILE *				fout)
{
	const char * const * sym;

	if (!uctx->syms[0])
		return 0;

	if ((pretty_header(cctx,fout)) < 0)
		return -1;

	for (sym=uctx->syms; *sym; sym++)
		if ((pretty_export_item(cctx,*sym,fout)) < 0)
			return -1;

	return 0;
}