Blame src/logic/linkcmd/slbt_linkcmd_host.c

c486f2
/*******************************************************************/
eac61a
/*  slibtool: a strong libtool implementation, written in C        */
49181b
/*  Copyright (C) 2016--2024  SysDeer Technologies, LLC            */
c486f2
/*  Released under the Standard MIT License; see COPYING.SLIBTOOL. */
c486f2
/*******************************************************************/
c486f2
c486f2
#include <stdlib.h>
c486f2
#include <stdio.h>
c486f2
#include <string.h>
c486f2
#include <fcntl.h>
c486f2
#include <errno.h>
c486f2
#include <sys/stat.h>
c486f2
c486f2
#include <slibtool/slibtool.h>
c486f2
#include "slibtool_driver_impl.h"
c486f2
#include "slibtool_errinfo_impl.h"
c486f2
#include "slibtool_linkcmd_impl.h"
c486f2
#include "slibtool_mapfile_impl.h"
c486f2
#include "slibtool_metafile_impl.h"
c486f2
#include "slibtool_snprintf_impl.h"
c486f2
#include "slibtool_symlink_impl.h"
4b56de
#include "slibtool_visibility_impl.h"
c486f2
4b56de
slbt_hidden int slbt_exec_link_create_host_tag(
c486f2
	const struct slbt_driver_ctx *	dctx,
c486f2
	struct slbt_exec_ctx *		ectx,
c486f2
	char *				deffilename)
c486f2
{
c486f2
	char *  slash;
c486f2
	char	hosttag[PATH_MAX];
c486f2
	char	hostlnk[PATH_MAX];
c486f2
c486f2
	/* libfoo.so.def.{flavor} */
c486f2
	if (slbt_snprintf(hosttag,
c486f2
			sizeof(hosttag),
c486f2
			"%s.%s",
c486f2
			deffilename,
c486f2
			dctx->cctx->host.flavor) < 0)
c486f2
		return SLBT_BUFFER_ERROR(dctx);
c486f2
c486f2
	if (slbt_snprintf(hostlnk,
c486f2
			sizeof(hostlnk),
c486f2
			"%s.host",
c486f2
			deffilename) < 0)
c486f2
		return SLBT_BUFFER_ERROR(dctx);
c486f2
c486f2
	/* libfoo.so.def is under .libs/ */
c486f2
	if (!(slash = strrchr(deffilename,'/')))
c486f2
		return SLBT_CUSTOM_ERROR(dctx,SLBT_ERR_LINK_FLOW);
c486f2
c486f2
	if (slbt_create_symlink(
c486f2
		dctx,ectx,
c486f2
		deffilename,
c486f2
		hosttag,
c486f2
		SLBT_SYMLINK_DEFAULT))
c486f2
	return SLBT_NESTED_ERROR(dctx);
c486f2
c486f2
	/* libfoo.so.def.{flavor} is under .libs/ */
c486f2
	if (!(slash = strrchr(hosttag,'/')))
c486f2
		return SLBT_CUSTOM_ERROR(dctx,SLBT_ERR_LINK_FLOW);
c486f2
c486f2
	if (slbt_create_symlink(
c486f2
			dctx,ectx,
c486f2
			++slash,
c486f2
			hostlnk,
c486f2
			SLBT_SYMLINK_DEFAULT))
c486f2
		return SLBT_NESTED_ERROR(dctx);
c486f2
c486f2
	return 0;
c486f2
}