From 8dc63ddc326ec54709c580a400536fcc4ef62622 Mon Sep 17 00:00:00 2001 From: midipix Date: Mon, 19 Feb 2024 01:54:51 +0000 Subject: library api's: _util_ (utility helper interfaces) namespace overhaul. --- src/util/slbt_copy_file.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/util/slbt_copy_file.c (limited to 'src/util/slbt_copy_file.c') diff --git a/src/util/slbt_copy_file.c b/src/util/slbt_copy_file.c new file mode 100644 index 0000000..30d3f03 --- /dev/null +++ b/src/util/slbt_copy_file.c @@ -0,0 +1,76 @@ +/*******************************************************************/ +/* slibtool: a skinny libtool implementation, written in C */ +/* Copyright (C) 2016--2024 SysDeer Technologies, LLC */ +/* Released under the Standard MIT License; see COPYING.SLIBTOOL. */ +/*******************************************************************/ + +#include +#include "slibtool_driver_impl.h" +#include "slibtool_spawn_impl.h" +#include "slibtool_symlink_impl.h" +#include "slibtool_errinfo_impl.h" + +int slbt_util_copy_file( + const struct slbt_driver_ctx * dctx, + struct slbt_exec_ctx * ectx, + char * src, + char * dst) +{ + int fdcwd; + char ** oargv; + char * oprogram; + char * cp[4]; + int ret; + + /* fdcwd */ + fdcwd = slbt_driver_fdcwd(dctx); + + /* placeholder? */ + if (slbt_symlink_is_a_placeholder(fdcwd,src)) + return 0; + + /* cp argv */ + cp[0] = "cp"; + cp[1] = src; + cp[2] = dst; + cp[3] = 0; + + /* alternate argument vector */ + oprogram = ectx->program; + oargv = ectx->argv; + ectx->argv = cp; + ectx->program = "cp"; + + /* step output */ + if (!(dctx->cctx->drvflags & SLBT_DRIVER_SILENT)) { + if (dctx->cctx->mode == SLBT_MODE_LINK) { + if (slbt_output_link(dctx,ectx)) { + ectx->argv = oargv; + ectx->program = oprogram; + return SLBT_NESTED_ERROR(dctx); + } + } else { + if (slbt_output_install(dctx,ectx)) { + ectx->argv = oargv; + ectx->program = oprogram; + return SLBT_NESTED_ERROR(dctx); + } + } + } + + /* cp spawn */ + if ((slbt_spawn(ectx,true) < 0) && (ectx->pid < 0)) { + ret = SLBT_SPAWN_ERROR(dctx); + + } else if (ectx->exitcode) { + ret = SLBT_CUSTOM_ERROR( + dctx, + SLBT_ERR_COPY_ERROR); + } else { + ret = 0; + } + + ectx->argv = oargv; + ectx->program = oprogram; + return ret; +} -- cgit v1.2.3