Blame src/arbits/output/slbt_ar_output_mapfile.c

a740e6
/*******************************************************************/
a740e6
/*  slibtool: a skinny libtool implementation, written in C        */
a740e6
/*  Copyright (C) 2016--2024  SysDeer Technologies, LLC            */
a740e6
/*  Released under the Standard MIT License; see COPYING.SLIBTOOL. */
a740e6
/*******************************************************************/
a740e6
a740e6
#include <time.h>
a740e6
#include <locale.h>
a740e6
#include <regex.h>
a740e6
#include <inttypes.h>
a740e6
#include <slibtool/slibtool.h>
a740e6
#include <slibtool/slibtool_output.h>
a740e6
#include "slibtool_driver_impl.h"
a740e6
#include "slibtool_dprintf_impl.h"
a740e6
#include "slibtool_errinfo_impl.h"
a740e6
#include "slibtool_ar_impl.h"
a740e6
a740e6
static int slbt_ar_output_mapfile_impl(
a740e6
	const struct slbt_driver_ctx *  dctx,
a740e6
	struct slbt_archive_meta_impl * mctx,
a740e6
	const struct slbt_fd_ctx *      fdctx)
a740e6
{
a740e6
	int             fdout;
a740e6
	const char *    regex;
a740e6
	const char **   symv;
a740e6
	regex_t         regctx;
a740e6
	regmatch_t      pmatch[2] = {0};
a740e6
a740e6
	fdout = fdctx->fdout;
a740e6
a740e6
	if (slbt_dprintf(fdout,"{\n" "\t" "global:\n") < 0)
a740e6
		return SLBT_SYSTEM_ERROR(dctx,0);
a740e6
a740e6
	if ((regex = dctx->cctx->regex))
a740e6
		if (regcomp(&regctx,regex,REG_NEWLINE))
a740e6
			return SLBT_CUSTOM_ERROR(
a740e6
				dctx,
a740e6
				SLBT_ERR_FLOW_ERROR);
a740e6
a740e6
	for (symv=mctx->symstrv; *symv; symv++)
a740e6
		if (!regex || !regexec(&regctx,*symv,1,pmatch,0))
a740e6
			if (slbt_dprintf(fdout,"\t\t%s;\n",*symv) < 0)
a740e6
				return SLBT_SYSTEM_ERROR(dctx,0);
a740e6
a740e6
	if (regex)
a740e6
		regfree(&regctx);
a740e6
a740e6
	if (slbt_dprintf(fdout,"\n\t" "local:\n" "\t\t*;\n" "};\n") < 0)
a740e6
		return SLBT_SYSTEM_ERROR(dctx,0);
a740e6
a740e6
	return 0;
a740e6
}
a740e6
a740e6
int slbt_ar_output_mapfile(const struct slbt_archive_meta * meta)
a740e6
{
a740e6
	struct slbt_archive_meta_impl * mctx;
a740e6
	const struct slbt_driver_ctx *  dctx;
a740e6
	struct slbt_fd_ctx              fdctx;
a740e6
a740e6
	mctx = slbt_archive_meta_ictx(meta);
a740e6
	dctx = (slbt_archive_meta_ictx(meta))->dctx;
a740e6
a740e6
	if (slbt_get_driver_fdctx(dctx,&fdctx) < 0)
a740e6
		return SLBT_NESTED_ERROR(dctx);
a740e6
a740e6
	if (!meta->a_memberv)
a740e6
		return 0;
a740e6
a740e6
	return slbt_ar_output_mapfile_impl(
a740e6
		dctx,mctx,&fdctx);
a740e6
}