Blame src/helper/slbt_copy_file.c

13b6d8
/*******************************************************************/
13b6d8
/*  slibtool: a skinny libtool implementation, written in C        */
13b6d8
/*  Copyright (C) 2016  Z. Gilboa                                  */
13b6d8
/*  Released under the Standard MIT License; see COPYING.SLIBTOOL. */
13b6d8
/*******************************************************************/
13b6d8
13b6d8
#include <slibtool/slibtool.h>
13b6d8
#include "slibtool_spawn_impl.h"
42595b
#include "slibtool_errinfo_impl.h"
13b6d8
13b6d8
int slbt_copy_file(
13b6d8
	const struct slbt_driver_ctx *	dctx,
13b6d8
	struct slbt_exec_ctx *		ectx,
13b6d8
	char *				src,
13b6d8
	char *				dst)
13b6d8
{
d8d0e9
	char **	oargv;
9bf2c5
	char *	oprogram;
13b6d8
	char *	cp[4];
d8d0e9
	int	ret;
13b6d8
13b6d8
	/* cp argv */
13b6d8
	cp[0] = "cp";
13b6d8
	cp[1] = src;
13b6d8
	cp[2] = dst;
13b6d8
	cp[3] = 0;
13b6d8
13b6d8
	/* alternate argument vector */
9bf2c5
	oprogram      = ectx->program;
d8d0e9
	oargv         = ectx->argv;
13b6d8
	ectx->argv    = cp;
13b6d8
	ectx->program = "cp";
13b6d8
13b6d8
	/* step output */
d8d0e9
	if (!(dctx->cctx->drvflags & SLBT_DRIVER_SILENT)) {
0364b5
		if (dctx->cctx->mode == SLBT_MODE_LINK) {
0364b5
			if (slbt_output_link(dctx,ectx)) {
0364b5
				ectx->argv = oargv;
9bf2c5
				ectx->program = oprogram;
42595b
				return SLBT_NESTED_ERROR(dctx);
0364b5
			}
0364b5
		} else {
0364b5
			if (slbt_output_install(dctx,ectx)) {
0364b5
				ectx->argv = oargv;
9bf2c5
				ectx->program = oprogram;
42595b
				return SLBT_NESTED_ERROR(dctx);
0364b5
			}
d8d0e9
		}
d8d0e9
	}
13b6d8
13b6d8
	/* dlltool spawn */
d8d0e9
	ret = ((slbt_spawn(ectx,true) < 0) || ectx->exitcode)
42595b
		? SLBT_SYSTEM_ERROR(dctx) : 0;
13b6d8
d8d0e9
	ectx->argv = oargv;
9bf2c5
	ectx->program = oprogram;
d8d0e9
	return ret;
13b6d8
}