summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2016-04-08 12:53:52 -0400
committermidipix <writeonce@midipix.org>2016-04-08 12:53:52 -0400
commit6529aa199a616eaeb8f32841d29ec5afd7dcc4f4 (patch)
treecc962f2dbe65030454928522d42872003a268c5c
parent82142f33ca3209442426e56da24d9722adf4c8bb (diff)
downloadslibtool-6529aa199a616eaeb8f32841d29ec5afd7dcc4f4.tar.bz2
slibtool-6529aa199a616eaeb8f32841d29ec5afd7dcc4f4.tar.xz
internal: slbt_create_symlink(): initial implementation and integration.
-rw-r--r--project/common.mk1
-rw-r--r--project/headers.mk1
-rw-r--r--src/internal/slibtool_symlink_impl.c62
-rw-r--r--src/internal/slibtool_symlink_impl.h15
-rw-r--r--src/logic/slbt_exec_link.c50
5 files changed, 82 insertions, 47 deletions
diff --git a/project/common.mk b/project/common.mk
index fafad0f..06b9292 100644
--- a/project/common.mk
+++ b/project/common.mk
@@ -1,4 +1,5 @@
COMMON_SRCS = \
+ src/internal/slibtool_symlink_impl.c \
src/driver/slbt_driver_ctx.c \
src/driver/slbt_unit_ctx.c \
src/logic/slbt_exec_compile.c \
diff --git a/project/headers.mk b/project/headers.mk
index 119055a..803dbc7 100644
--- a/project/headers.mk
+++ b/project/headers.mk
@@ -6,5 +6,6 @@ INTERNAL_HEADERS = \
$(PROJECT_DIR)/src/internal/argv/argv.h \
$(PROJECT_DIR)/src/internal/$(PACKAGE)_driver_impl.h \
$(PROJECT_DIR)/src/internal/$(PACKAGE)_spawn_impl.h \
+ $(PROJECT_DIR)/src/internal/$(PACKAGE)_symlink_impl.h \
ALL_HEADERS = $(API_HEADERS) $(INTERNAL_HEADERS)
diff --git a/src/internal/slibtool_symlink_impl.c b/src/internal/slibtool_symlink_impl.c
new file mode 100644
index 0000000..88af538
--- /dev/null
+++ b/src/internal/slibtool_symlink_impl.c
@@ -0,0 +1,62 @@
+/*******************************************************************/
+/* slibtool: a skinny libtool implementation, written in C */
+/* Copyright (C) 2016 Z. Gilboa */
+/* Released under the Standard MIT License; see COPYING.SLIBTOOL. */
+/*******************************************************************/
+
+#include <stdio.h>
+#include <string.h>
+#include <stdbool.h>
+#include <unistd.h>
+
+#include "slibtool_symlink_impl.h"
+
+int slbt_create_symlink(
+ const struct slbt_driver_ctx * dctx,
+ struct slbt_exec_ctx * ectx,
+ const char * target,
+ char * lnkname,
+ bool flawrapper)
+{
+ const char * slash;
+ char * ln[5];
+ char * dotdot;
+ char tmplnk [PATH_MAX];
+ char atarget[PATH_MAX];
+
+ /* atarget */
+ if ((slash = strrchr(target,'/')))
+ slash++;
+ else
+ slash = target;
+
+ dotdot = flawrapper ? "../" : "";
+
+ if ((size_t)snprintf(atarget,sizeof(atarget),"%s%s",
+ dotdot,slash) >= sizeof(atarget))
+ return -1;
+
+ /* tmplnk */
+ if ((size_t)snprintf(tmplnk,sizeof(tmplnk),"%s.symlink.tmp",
+ lnkname) >= sizeof(tmplnk))
+ return -1;
+
+ /* ln argv (fake) */
+ ln[0] = "ln";
+ ln[1] = "-s";
+ ln[2] = atarget;
+ ln[3] = lnkname;
+ ln[4] = 0;
+ ectx->argv = ln;
+
+ /* step output */
+ if (!(dctx->cctx->drvflags & SLBT_DRIVER_SILENT))
+ if (slbt_output_link(dctx,ectx))
+ return -1;
+
+ /* create symlink */
+ if (symlink(atarget,tmplnk))
+ return -1;
+
+ return rename(tmplnk,lnkname);
+}
diff --git a/src/internal/slibtool_symlink_impl.h b/src/internal/slibtool_symlink_impl.h
new file mode 100644
index 0000000..5ca65d5
--- /dev/null
+++ b/src/internal/slibtool_symlink_impl.h
@@ -0,0 +1,15 @@
+/*******************************************************************/
+/* slibtool: a skinny libtool implementation, written in C */
+/* Copyright (C) 2016 Z. Gilboa */
+/* Released under the Standard MIT License; see COPYING.SLIBTOOL. */
+/*******************************************************************/
+
+#include <stdbool.h>
+#include <slibtool/slibtool.h>
+
+int slbt_create_symlink(
+ const struct slbt_driver_ctx * dctx,
+ struct slbt_exec_ctx * ectx,
+ const char * target,
+ char * lnkname,
+ bool flawrapper);
diff --git a/src/logic/slbt_exec_link.c b/src/logic/slbt_exec_link.c
index 5ffbc29..1a21da4 100644
--- a/src/logic/slbt_exec_link.c
+++ b/src/logic/slbt_exec_link.c
@@ -12,6 +12,7 @@
#include <slibtool/slibtool.h>
#include "slibtool_spawn_impl.h"
+#include "slibtool_symlink_impl.h"
/*******************************************************************/
/* */
@@ -503,51 +504,6 @@ static int slbt_exec_link_create_executable(
return 0;
}
-static int slbt_exec_link_create_symlink(
- const struct slbt_driver_ctx * dctx,
- struct slbt_exec_ctx * ectx,
- const char * target,
- char * lnkname,
- bool flawrapper)
-{
- const char * slash;
- char * ln[5];
- char * dotdot;
- char atarget[PATH_MAX];
-
- /* atarget */
- if ((slash = strrchr(target,'/')))
- slash++;
- else
- slash = target;
-
- dotdot = flawrapper ? "../" : "";
-
- if ((size_t)snprintf(atarget,sizeof(atarget),"%s%s",
- dotdot,slash) >= sizeof(atarget))
- return -1;
-
- /* ln argv (fake) */
- ln[0] = "ln";
- ln[1] = "-s";
- ln[2] = atarget;
- ln[3] = lnkname;
- ln[4] = 0;
- ectx->argv = ln;
-
- /* step output */
- if (!(dctx->cctx->drvflags & SLBT_DRIVER_SILENT))
- if (slbt_output_link(dctx,ectx))
- return -1;
-
- /* remove old symlink as needed */
- if (slbt_exec_link_remove_file(dctx,ectx,lnkname))
- return -1;
-
- /* create symlink */
- return symlink(atarget,lnkname);
-}
-
static int slbt_exec_link_create_library_symlink(
const struct slbt_driver_ctx * dctx,
struct slbt_exec_ctx * ectx,
@@ -570,7 +526,7 @@ static int slbt_exec_link_create_library_symlink(
else
strcpy(lnkname,ectx->dsofilename);
- return slbt_exec_link_create_symlink(
+ return slbt_create_symlink(
dctx,ectx,
target,lnkname,
false);
@@ -677,7 +633,7 @@ int slbt_exec_link(
}
/* wrapper symlink */
- if (slbt_exec_link_create_symlink(
+ if (slbt_create_symlink(
dctx,ectx,
output,
ectx->lafilename,