summaryrefslogtreecommitdiffhomepage
path: root/src/output/mdso_output_export_symbols.c
blob: fefb6ce52b4af99f98c4471b4037b10425181e37 (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
50
51
52
53
54
55
56
57
/****************************************************************/
/*  mdso: midipix dso scavenger                                 */
/*  Copyright (C) 2015--2021  SysDeer Technologies, LLC         */
/*  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>
#include "mdso_driver_impl.h"
#include "mdso_dprintf_impl.h"
#include "mdso_errinfo_impl.h"

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

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

int mdso_output_export_symbols(
	const struct mdso_driver_ctx *	dctx,
	const struct mdso_unit_ctx *	uctx)
{
	int			fdout;
	const char * const *	sym;

	fdout = mdso_driver_fdout(dctx);

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

	if ((pretty_header(fdout,dctx->cctx)) < 0)
		return MDSO_SYSTEM_ERROR(dctx);

	for (sym=uctx->syms; *sym; sym++)
		if ((pretty_export_item(fdout,dctx->cctx,*sym)) < 0)
			return MDSO_SYSTEM_ERROR(dctx);

	return 0;
}