summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2024-02-21 06:18:44 +0000
committermidipix <writeonce@midipix.org>2024-02-21 06:18:44 +0000
commitfc7ad9f9947b5097e1a246b009b487d3206fd588 (patch)
treeaca1e2b8f1099337d76db36afc83cbeba4750b8a /src
parent5b993e0818b603c1dec4126dfe45c617619eff93 (diff)
downloadslibtool-fc7ad9f9947b5097e1a246b009b487d3206fd588.tar.bz2
slibtool-fc7ad9f9947b5097e1a246b009b487d3206fd588.tar.xz
slbt_util_copy_file(): simplify interface.
Diffstat (limited to 'src')
-rw-r--r--src/internal/slibtool_symlink_impl.c2
-rw-r--r--src/internal/slibtool_symlink_impl.h2
-rw-r--r--src/logic/slbt_exec_install.c11
-rw-r--r--src/logic/slbt_exec_link.c2
-rw-r--r--src/util/slbt_copy_file.c32
5 files changed, 35 insertions, 14 deletions
diff --git a/src/internal/slibtool_symlink_impl.c b/src/internal/slibtool_symlink_impl.c
index c9be845..a788800 100644
--- a/src/internal/slibtool_symlink_impl.c
+++ b/src/internal/slibtool_symlink_impl.c
@@ -131,7 +131,7 @@ slbt_hidden int slbt_create_symlink(
: 0;
}
-slbt_hidden int slbt_symlink_is_a_placeholder(int fdcwd, char * lnkpath)
+slbt_hidden int slbt_symlink_is_a_placeholder(int fdcwd, const char * lnkpath)
{
size_t len;
char slink [PATH_MAX];
diff --git a/src/internal/slibtool_symlink_impl.h b/src/internal/slibtool_symlink_impl.h
index fc4c708..14ddead 100644
--- a/src/internal/slibtool_symlink_impl.h
+++ b/src/internal/slibtool_symlink_impl.h
@@ -16,6 +16,6 @@ int slbt_create_symlink(
const char * lnkname,
uint32_t options);
-int slbt_symlink_is_a_placeholder(int fdcwd, char * lnkpath);
+int slbt_symlink_is_a_placeholder(int fdcwd, const char * lnkpath);
#endif
diff --git a/src/logic/slbt_exec_install.c b/src/logic/slbt_exec_install.c
index 20cf679..ddd3a60 100644
--- a/src/logic/slbt_exec_install.c
+++ b/src/logic/slbt_exec_install.c
@@ -191,7 +191,7 @@ static int slbt_exec_install_import_libraries(
dctx->cctx->asettings.impsuffix);
/* copy: .libs/libfoo.x.y.z.lib.a --> dstdir */
- if (slbt_util_copy_file(dctx,ectx,srcbuf,dstdir))
+ if (slbt_util_copy_file(ectx,srcbuf,dstdir))
return SLBT_NESTED_ERROR(dctx);
/* .libs/libfoo.x.lib.a */
@@ -200,7 +200,7 @@ static int slbt_exec_install_import_libraries(
dctx->cctx->asettings.impsuffix);
/* copy: .libs/libfoo.x.lib.a --> dstdir */
- if (slbt_util_copy_file(dctx,ectx,srcbuf,dstdir))
+ if (slbt_util_copy_file(ectx,srcbuf,dstdir))
return SLBT_NESTED_ERROR(dctx);
/* /dstdir/libfoo.lib.a */
@@ -310,7 +310,7 @@ static int slbt_exec_install_library_wrapper(
slbt_unmap_file(mapinfo);
/* cp libfoo.la.slibtool.instal /dstdir/libfoo.la */
- if (slbt_util_copy_file(dctx,ectx,clainame,instname))
+ if (slbt_util_copy_file(ectx,clainame,instname))
return SLBT_NESTED_ERROR(dctx);
return 0;
@@ -555,7 +555,8 @@ static int slbt_exec_install_entry(
farchive = false;
if (farchive)
- if (slbt_util_copy_file(dctx,ectx,
+ if (slbt_util_copy_file(
+ ectx,
srcfile,
dest ? (char *)dest->arg : *dst))
return SLBT_NESTED_ERROR(dctx);
@@ -683,7 +684,7 @@ static int slbt_exec_install_entry(
if (fpe) {
/* copy: .libs/libfoo.so.x.y.z --> libfoo.so.x */
if (slbt_util_copy_file(
- dctx,ectx,
+ ectx,
srcfile,
dlnkname))
return SLBT_NESTED_ERROR(dctx);
diff --git a/src/logic/slbt_exec_link.c b/src/logic/slbt_exec_link.c
index 4545110..428c13a 100644
--- a/src/logic/slbt_exec_link.c
+++ b/src/logic/slbt_exec_link.c
@@ -120,7 +120,7 @@ static int slbt_exec_link_create_library_symlink(
if (fmajor && (dctx->cctx->drvflags & SLBT_DRIVER_IMAGE_PE))
return slbt_util_copy_file(
- dctx,ectx,
+ ectx,
target,lnkname);
else
return slbt_create_symlink(
diff --git a/src/util/slbt_copy_file.c b/src/util/slbt_copy_file.c
index e6868de..3fa0074 100644
--- a/src/util/slbt_copy_file.c
+++ b/src/util/slbt_copy_file.c
@@ -11,24 +11,39 @@
#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)
+ struct slbt_exec_ctx * ectx,
+ const char * from,
+ const char * to)
{
+ int ret;
int fdcwd;
char ** oargv;
char * oprogram;
+ char * src;
+ char * dst;
char * cp[4];
- int ret;
+
+ const struct slbt_driver_ctx * dctx;
+
+ /* driver context */
+ dctx = (slbt_get_exec_ictx(ectx))->dctx;
/* fdcwd */
fdcwd = slbt_driver_fdcwd(dctx);
/* placeholder? */
- if (slbt_symlink_is_a_placeholder(fdcwd,src))
+ if (slbt_symlink_is_a_placeholder(fdcwd,from))
return 0;
+ /* until we perform an in-memory copy ... */
+ if (!(src = strdup(from)))
+ return SLBT_SYSTEM_ERROR(dctx,0);
+
+ if (!(dst = strdup(to))) {
+ free(src);
+ return SLBT_SYSTEM_ERROR(dctx,0);
+ }
+
/* cp argv */
cp[0] = "cp";
cp[1] = src;
@@ -47,12 +62,14 @@ int slbt_util_copy_file(
if (slbt_output_link(ectx)) {
ectx->argv = oargv;
ectx->program = oprogram;
+ free(src); free(dst);
return SLBT_NESTED_ERROR(dctx);
}
} else {
if (slbt_output_install(ectx)) {
ectx->argv = oargv;
ectx->program = oprogram;
+ free(src); free(dst);
return SLBT_NESTED_ERROR(dctx);
}
}
@@ -70,6 +87,9 @@ int slbt_util_copy_file(
ret = 0;
}
+ free(src);
+ free(dst);
+
ectx->argv = oargv;
ectx->program = oprogram;
return ret;