Blame src/arbits/slbt_archive_mapstrv.c

df2627
/*******************************************************************/
eac61a
/*  slibtool: a strong libtool implementation, written in C        */
df2627
/*  Copyright (C) 2016--2024  SysDeer Technologies, LLC            */
df2627
/*  Released under the Standard MIT License; see COPYING.SLIBTOOL. */
df2627
/*******************************************************************/
df2627
df2627
#include <stdlib.h>
df2627
#include <inttypes.h>
df2627
#include <slibtool/slibtool.h>
df2627
#include "slibtool_driver_impl.h"
df2627
#include "slibtool_errinfo_impl.h"
4b56de
#include "slibtool_visibility_impl.h"
df2627
#include "slibtool_ar_impl.h"
886c09
#include "slibtool_coff_impl.h"
df2627
fbd10d
static int slbt_qsort_strcmp(const void * a, const void * b)
df2627
{
df2627
	return strcmp(*(const char **)a,*(const char **)b);
df2627
}
df2627
4b56de
slbt_hidden int slbt_update_mapstrv(
df2627
	const struct slbt_driver_ctx *  dctx,
df2627
	struct slbt_archive_meta_impl * mctx)
df2627
{
213eb3
	bool            fcoff;
df2627
	size_t          nsyms;
df2627
	const char **   symv;
df2627
	const char **   mapstrv;
df2627
213eb3
	fcoff  = slbt_host_objfmt_is_coff(dctx);
213eb3
	fcoff |= (mctx->ofmtattr & AR_OBJECT_ATTR_COFF);
213eb3
df2627
	for (nsyms=0,symv=mctx->symstrv; *symv; symv++)
df2627
		nsyms++;
df2627
df2627
	if (!(mapstrv = calloc(nsyms+1,sizeof(const char *))))
df2627
		return SLBT_SYSTEM_ERROR(dctx,0);
df2627
df2627
	for (nsyms=0,symv=mctx->symstrv; *symv; symv++)
df2627
		mapstrv[nsyms++] = *symv;
df2627
fbd10d
	qsort(mapstrv,nsyms,sizeof(const char *),fcoff ? slbt_coff_qsort_strcmp : slbt_qsort_strcmp);
df2627
df2627
	mctx->mapstrv = mapstrv;
df2627
df2627
	return 0;
df2627
}