Blame src/output/mdso_output_export_symbols.c

8cfad6
/****************************************************************/
8cfad6
/*  mdso: midipix dso scavenger                                 */
473806
/*  Copyright (C) 2015--2024  SysDeer Technologies, LLC         */
8cfad6
/*  Released under GPLv2 and GPLv3; see COPYING.MDSO.           */
8cfad6
/****************************************************************/
8cfad6
8cfad6
#include <stdint.h>
8cfad6
#include <stdlib.h>
8cfad6
#include <stdio.h>
8cfad6
#include <string.h>
8cfad6
#include <errno.h>
8cfad6
8cfad6
#include <mdso/mdso.h>
8cfad6
#include <mdso/mdso_output.h>
551500
#include "mdso_driver_impl.h"
551500
#include "mdso_dprintf_impl.h"
63e310
#include "mdso_errinfo_impl.h"
8cfad6
551500
static int pretty_header(int fdout, const struct mdso_common_ctx * cctx)
8cfad6
{
8cfad6
	return (cctx->fmtflags & MDSO_PRETTY_YAML)
551500
		? mdso_dprintf(fdout,"exports:\n")
8cfad6
		: 0;
8cfad6
}
8cfad6
551500
static int pretty_export_item(
551500
	int				fdout,
551500
	const struct mdso_common_ctx *	cctx,
551500
	const char *			name)
8cfad6
{
8cfad6
	if (cctx->fmtflags & MDSO_PRETTY_YAML)
551500
		return mdso_dprintf(fdout,"- %s\n",name);
8cfad6
	else
551500
		return mdso_dprintf(fdout,"%s\n",name);
8cfad6
}
8cfad6
8cfad6
int mdso_output_export_symbols(
63e310
	const struct mdso_driver_ctx *	dctx,
551500
	const struct mdso_unit_ctx *	uctx)
8cfad6
{
551500
	int			fdout;
551500
	const char * const *	sym;
551500
551500
	fdout = mdso_driver_fdout(dctx);
8cfad6
8cfad6
	if (!uctx->syms[0])
8cfad6
		return 0;
8cfad6
551500
	if ((pretty_header(fdout,dctx->cctx)) < 0)
551500
		return MDSO_SYSTEM_ERROR(dctx);
8cfad6
8cfad6
	for (sym=uctx->syms; *sym; sym++)
551500
		if ((pretty_export_item(fdout,dctx->cctx,*sym)) < 0)
551500
			return MDSO_SYSTEM_ERROR(dctx);
8cfad6
8cfad6
	return 0;
8cfad6
}