From 13b6d8f84c98ab31309f5653fe158022ea986a23 Mon Sep 17 00:00:00 2001 From: midipix Date: Apr 18 2016 23:58:54 +0000 Subject: library: helper functions: added slbt_copy_file. --- diff --git a/include/slibtool/slibtool.h b/include/slibtool/slibtool.h index 70ceef9..533be58 100644 --- a/include/slibtool/slibtool.h +++ b/include/slibtool/slibtool.h @@ -217,6 +217,8 @@ slbt_api int slbt_map_input (int fd, const char * path, int prot, struct slbt_ slbt_api int slbt_unmap_input (struct slbt_input *); slbt_api int slbt_archive_import (const struct slbt_driver_ctx *, struct slbt_exec_ctx *, char * dstarchive, char * srcarchive); +slbt_api int slbt_copy_file (const struct slbt_driver_ctx *, struct slbt_exec_ctx *, + char * src, char * dst); /* utility api */ slbt_api int slbt_output_config (const struct slbt_driver_ctx *); diff --git a/project/common.mk b/project/common.mk index ae06f28..6a8c3f1 100644 --- a/project/common.mk +++ b/project/common.mk @@ -3,6 +3,7 @@ COMMON_SRCS = \ src/driver/slbt_driver_ctx.c \ src/driver/slbt_unit_ctx.c \ src/helper/slbt_archive_import.c \ + src/helper/slbt_copy_file.c \ src/logic/slbt_exec_compile.c \ src/logic/slbt_exec_ctx.c \ src/logic/slbt_exec_install.c \ diff --git a/src/helper/slbt_copy_file.c b/src/helper/slbt_copy_file.c new file mode 100644 index 0000000..fb44dc7 --- /dev/null +++ b/src/helper/slbt_copy_file.c @@ -0,0 +1,38 @@ +/*******************************************************************/ +/* slibtool: a skinny libtool implementation, written in C */ +/* Copyright (C) 2016 Z. Gilboa */ +/* Released under the Standard MIT License; see COPYING.SLIBTOOL. */ +/*******************************************************************/ + +#include +#include "slibtool_spawn_impl.h" + +int slbt_copy_file( + const struct slbt_driver_ctx * dctx, + struct slbt_exec_ctx * ectx, + char * src, + char * dst) +{ + char * cp[4]; + + /* cp argv */ + cp[0] = "cp"; + cp[1] = src; + cp[2] = dst; + cp[3] = 0; + + /* alternate argument vector */ + ectx->argv = cp; + ectx->program = "cp"; + + /* step output */ + if (!(dctx->cctx->drvflags & SLBT_DRIVER_SILENT)) + if (slbt_output_link(dctx,ectx)) + return -1; + + /* dlltool spawn */ + if ((slbt_spawn(ectx,true) < 0) || ectx->exitcode) + return -1; + + return 0; +}