|
|
13b6d8 |
/*******************************************************************/
|
|
|
13b6d8 |
/* slibtool: a skinny libtool implementation, written in C */
|
|
|
49181b |
/* Copyright (C) 2016--2024 SysDeer Technologies, LLC */
|
|
|
13b6d8 |
/* Released under the Standard MIT License; see COPYING.SLIBTOOL. */
|
|
|
13b6d8 |
/*******************************************************************/
|
|
|
13b6d8 |
|
|
|
13b6d8 |
#include <slibtool/slibtool.h>
|
|
|
c81d16 |
#include "slibtool_driver_impl.h"
|
|
|
13b6d8 |
#include "slibtool_spawn_impl.h"
|
|
|
127b94 |
#include "slibtool_symlink_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 |
{
|
|
|
c81d16 |
int fdcwd;
|
|
|
d8d0e9 |
char ** oargv;
|
|
|
9bf2c5 |
char * oprogram;
|
|
|
13b6d8 |
char * cp[4];
|
|
|
d8d0e9 |
int ret;
|
|
|
13b6d8 |
|
|
|
c81d16 |
/* fdcwd */
|
|
|
c81d16 |
fdcwd = slbt_driver_fdcwd(dctx);
|
|
|
c81d16 |
|
|
|
127b94 |
/* placeholder? */
|
|
|
c81d16 |
if (slbt_symlink_is_a_placeholder(fdcwd,src))
|
|
|
127b94 |
return 0;
|
|
|
127b94 |
|
|
|
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 |
|
|
|
fcfea7 |
/* cp spawn */
|
|
|
fcfea7 |
if ((slbt_spawn(ectx,true) < 0) && (ectx->pid < 0)) {
|
|
|
fcfea7 |
ret = SLBT_SPAWN_ERROR(dctx);
|
|
|
fcfea7 |
|
|
|
fcfea7 |
} else if (ectx->exitcode) {
|
|
|
fcfea7 |
ret = SLBT_CUSTOM_ERROR(
|
|
|
fcfea7 |
dctx,
|
|
|
fcfea7 |
SLBT_ERR_COPY_ERROR);
|
|
|
fcfea7 |
} else {
|
|
|
fcfea7 |
ret = 0;
|
|
|
fcfea7 |
}
|
|
|
13b6d8 |
|
|
|
d8d0e9 |
ectx->argv = oargv;
|
|
|
9bf2c5 |
ectx->program = oprogram;
|
|
|
d8d0e9 |
return ret;
|
|
|
13b6d8 |
}
|