firasuke / cross / slibtool

Forked from cross/slibtool a month ago
Clone

Blame src/util/slbt_archive_import.c

4a01cf
/*******************************************************************/
4a01cf
/*  slibtool: a skinny libtool implementation, written in C        */
49181b
/*  Copyright (C) 2016--2024  SysDeer Technologies, LLC            */
4a01cf
/*  Released under the Standard MIT License; see COPYING.SLIBTOOL. */
4a01cf
/*******************************************************************/
4a01cf
4a01cf
#include <slibtool/slibtool.h>
c81d16
#include "slibtool_driver_impl.h"
c1e423
#include "slibtool_symlink_impl.h"
8a1d14
#include "slibtool_errinfo_impl.h"
4a01cf
89caff
/* legacy fallback, no longer in use */
8dc63d
extern int slbt_util_import_archive_mri(
5b993e
	struct slbt_exec_ctx *  ectx,
5b993e
	char *			dstarchive,
5b993e
	char *			srcarchive);
4a01cf
89caff
/* use slibtool's in-memory archive merging facility */
8dc63d
static int slbt_util_import_archive_impl(
f3e7bb
	const struct slbt_driver_ctx *  dctx,
f3e7bb
	const struct slbt_exec_ctx *	ectx,
89caff
	char *				dstarchive,
89caff
	char *				srcarchive)
89caff
{
89caff
	int                             ret;
89caff
	struct slbt_archive_ctx *       arctxv[3] = {0,0,0};
89caff
	struct slbt_archive_ctx *       arctx;
89caff
89caff
	(void)ectx;
89caff
51c276
	if (slbt_ar_get_archive_ctx(dctx,dstarchive,&arctxv[0]) < 0)
89caff
		return SLBT_NESTED_ERROR(dctx);
89caff
51c276
	if (slbt_ar_get_archive_ctx(dctx,srcarchive,&arctxv[1]) < 0) {
51c276
		slbt_ar_free_archive_ctx(arctxv[0]);
89caff
		return SLBT_NESTED_ERROR(dctx);
89caff
	}
89caff
51c276
	ret = slbt_ar_merge_archives(arctxv,&arctx);
89caff
51c276
	slbt_ar_free_archive_ctx(arctxv[0]);
51c276
	slbt_ar_free_archive_ctx(arctxv[1]);
89caff
89caff
	if (ret == 0) {
51c276
		ret = slbt_ar_store_archive(arctx,dstarchive,0644);
51c276
		slbt_ar_free_archive_ctx(arctx);
89caff
	}
89caff
89caff
	return (ret < 0) ? SLBT_NESTED_ERROR(dctx) : 0;
89caff
}
89caff
89caff
8dc63d
int slbt_util_import_archive(
f3e7bb
	const struct slbt_exec_ctx *    ectx,
4a01cf
	char *				dstarchive,
4a01cf
	char *				srcarchive)
4a01cf
{
f3e7bb
	const struct slbt_driver_ctx *	dctx;
f3e7bb
f3e7bb
	dctx = (slbt_get_exec_ictx(ectx))->dctx;
f3e7bb
c1e423
	if (slbt_symlink_is_a_placeholder(
c1e423
			slbt_driver_fdcwd(dctx),
c1e423
			srcarchive))
c1e423
		return 0;
c1e423
8dc63d
	return slbt_util_import_archive_impl(
65cb35
		dctx,ectx,
65cb35
		dstarchive,
65cb35
		srcarchive);
4a01cf
}