summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2018-06-28 09:34:44 -0400
committermidipix <writeonce@midipix.org>2018-06-29 01:37:43 -0400
commit05ea52ac8079f8acc8d68524401f7afae4c89209 (patch)
tree0588c7f5db7c38ca25b8395c2fc6c98145b0bab6
parent50fd60861c53128bcd8a86d4ba39cfb68b5516cf (diff)
downloadslibtool-05ea52ac8079f8acc8d68524401f7afae4c89209.tar.bz2
slibtool-05ea52ac8079f8acc8d68524401f7afae4c89209.tar.xz
link mode: re-implemented slbt_get_deps_meta() w. pure fdio.
-rw-r--r--src/logic/slbt_exec_link.c72
1 files changed, 31 insertions, 41 deletions
diff --git a/src/logic/slbt_exec_link.c b/src/logic/slbt_exec_link.c
index 76c9cdc..e91ae98 100644
--- a/src/logic/slbt_exec_link.c
+++ b/src/logic/slbt_exec_link.c
@@ -16,6 +16,7 @@
#include "slibtool_spawn_impl.h"
#include "slibtool_mkdir_impl.h"
#include "slibtool_errinfo_impl.h"
+#include "slibtool_mapfile_impl.h"
#include "slibtool_metafile_impl.h"
#include "slibtool_readlink_impl.h"
#include "slibtool_symlink_impl.h"
@@ -83,72 +84,61 @@ static int slbt_get_deps_meta(
char * libfilename,
struct slbt_deps_meta * depsmeta)
{
- int ret;
- FILE * fdeps;
- struct stat st;
- char * deplib;
- char depfile[4*PATH_MAX];
- char * deplibs = depfile;
- char * base;
- size_t libexlen;
-
- (void)dctx;
+ char * ch;
+ char * cap;
+ char * base;
+ size_t libexlen;
+ struct stat st;
+ struct slbt_map_info * mapinfo;
+ char depfile[PATH_MAX];
/* -rpath */
- if ((size_t)snprintf(depfile,sizeof(depfile),"%s.slibtool.rpath",
+ if ((size_t)snprintf(depfile,sizeof(depfile),
+ "%s.slibtool.rpath",
libfilename)
>= sizeof(depfile))
return SLBT_BUFFER_ERROR(dctx);
+ /* -Wl,%s */
if (!(lstat(depfile,&st))) {
- /* -Wl,%s */
depsmeta->infolen += st.st_size + 4;
depsmeta->infolen++;
}
/* .deps */
- if ((size_t)snprintf(depfile,sizeof(depfile),"%s.slibtool.deps",
+ if ((size_t)snprintf(depfile,sizeof(depfile),
+ "%s.slibtool.deps",
libfilename)
>= sizeof(depfile))
return SLBT_BUFFER_ERROR(dctx);
- if ((stat(depfile,&st)))
+ /* mapinfo */
+ if (!(mapinfo = slbt_map_file(AT_FDCWD,depfile,SLBT_MAP_INPUT)))
return SLBT_SYSTEM_ERROR(dctx);
- if (!(fdeps = fopen(depfile,"r")))
- return SLBT_SYSTEM_ERROR(dctx);
-
- if ((size_t)st.st_size >= sizeof(depfile))
- if (!(deplibs = malloc(st.st_size+1))) {
- fclose(fdeps);
- return SLBT_SYSTEM_ERROR(dctx);
- }
-
- depsmeta->infolen += st.st_size;
+ /* copied length */
+ depsmeta->infolen += mapinfo->size;
depsmeta->infolen++;
- deplib = st.st_size
- ? fgets(deplibs,st.st_size+1,fdeps)
- : 0;
+ /* libexlen */
+ libexlen = (base = strrchr(libfilename,'/'))
+ ? strlen(depfile) + 2 + (base - libfilename)
+ : strlen(depfile) + 2;
- if ((base = strrchr(libfilename,'/')))
- libexlen = strlen(depfile) + base - libfilename + 2;
- else
- libexlen = strlen(depfile) + 2;
+ /* iterate */
+ ch = mapinfo->addr;
+ cap = mapinfo->cap;
- for (; deplib; ) {
- depsmeta->infolen += libexlen;
- depsmeta->depscnt++;
- deplib = fgets(deplibs,st.st_size+1,fdeps);
+ for (; ch<cap; ) {
+ if (*ch++ == 'n') {
+ depsmeta->infolen += libexlen;
+ depsmeta->depscnt++;
+ }
}
- if (deplibs != depfile)
- free(deplibs);
+ slbt_unmap_file(mapinfo);
- ret = ferror(fdeps) ? SLBT_FILE_ERROR(dctx) : 0;
- fclose(fdeps);
-
- return ret;
+ return 0;
}
static bool slbt_adjust_input_argument(