summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2018-06-28 14:00:09 -0400
committermidipix <writeonce@midipix.org>2018-06-29 01:37:43 -0400
commit9ae217c7e600b15415e84f9a0cf0510d9130ac55 (patch)
tree90becff70fbcd7e3b88851432f02ebecb9893c7e /src
parentb332ad32aa9c28702d3ce4d55d73ab7cabca0b24 (diff)
downloadslibtool-9ae217c7e600b15415e84f9a0cf0510d9130ac55.tar.bz2
slibtool-9ae217c7e600b15415e84f9a0cf0510d9130ac55.tar.xz
link mode: re-implemented slbt_exec_link_adjust_argument_vector() w. pure fdio.
Diffstat (limited to 'src')
-rw-r--r--src/logic/slbt_exec_link.c163
1 files changed, 73 insertions, 90 deletions
diff --git a/src/logic/slbt_exec_link.c b/src/logic/slbt_exec_link.c
index 749a224..8c70bcb 100644
--- a/src/logic/slbt_exec_link.c
+++ b/src/logic/slbt_exec_link.c
@@ -240,27 +240,27 @@ static int slbt_exec_link_adjust_argument_vector(
const char * cwd,
bool flibrary)
{
- char ** carg;
- char ** aarg;
- char * ldir;
- char * slash;
- char * mark;
- char * darg;
- char * dot;
- char * dep;
- char * base;
- FILE * fdeps;
- char * dpath;
- bool freqd;
- int argc;
- char arg[PATH_MAX];
- char lib[PATH_MAX];
- char depdir [PATH_MAX];
- char rpathdir[PATH_MAX];
- char rpathlnk[PATH_MAX];
- bool fwholearchive = false;
- struct stat st;
- int fd;
+ int fd;
+ char ** carg;
+ char ** aarg;
+ char * ldir;
+ char * slash;
+ char * mark;
+ char * darg;
+ char * dot;
+ char * base;
+ char * dpath;
+ int argc;
+ char arg[PATH_MAX];
+ char lib[PATH_MAX];
+ char depdir [PATH_MAX];
+ char rpathdir[PATH_MAX];
+ char rpathlnk[PATH_MAX];
+ struct stat st;
+ size_t size;
+ size_t dlen;
+ struct slbt_map_info * mapinfo;
+ bool fwholearchive = false;
for (argc=0,carg=ectx->cargv; *carg; carg++)
argc++;
@@ -279,10 +279,10 @@ static int slbt_exec_link_adjust_argument_vector(
carg = ectx->cargv;
aarg = depsmeta->altv;
darg = depsmeta->args;
+ size = depsmeta->infolen;
for (; *carg; ) {
dpath = 0;
- freqd = false;
if (!strcmp(*carg,"-Wl,--whole-archive"))
fwholearchive = true;
@@ -366,7 +366,6 @@ static int slbt_exec_link_adjust_argument_vector(
}
dpath = lib;
- freqd = true;
sprintf(lib,"%s.slibtool.deps",*carg);
/* account for {'-','L','-','l'} */
@@ -409,79 +408,63 @@ static int slbt_exec_link_adjust_argument_vector(
}
}
- if (dpath) {
- if (!stat(dpath,&st) && (fdeps = fopen(dpath,"r"))) {
- dep = st.st_size
- ? fgets(darg,st.st_size+1,fdeps)
- : 0;
-
- if (!(strncmp(lib,".libs/",6))) {
- *aarg++ = "-L.libs";
- lib[1] = 0;
- } else if ((base = strrchr(lib,'/'))) {
- if (base - lib == 5) {
- if (!(strncmp(&base[-5],".libs/",6)))
- base -= 4;
-
- } else if (base - lib >= 6) {
- if (!(strncmp(&base[-6],"/.libs/",7)))
- base -= 6;
- }
-
- *base = 0;
- } else {
- lib[0] = '.';
- lib[1] = 0;
- }
-
- for (; dep; ) {
- *aarg++ = darg;
- mark = darg;
- darg += strlen(dep);
-
- if (darg[-1] == '\n')
- darg[-1] = 0;
- else
- darg++;
-
- /* handle -L... as needed */
- if ((mark[0] == '-')
- && (mark[1] == 'L')
- && (mark[2] != '/')) {
- if (strlen(mark) >= sizeof(depdir) - 1)
- return slbt_exec_link_exit(
- depsmeta,
- SLBT_BUFFER_ERROR(dctx));
-
- darg = mark;
- strcpy(depdir,&mark[2]);
- sprintf(darg,"-L%s/%s",lib,depdir);
-
- darg += strlen(darg);
- darg++;
- }
-
- dep = fgets(darg,st.st_size+1,fdeps);
+ if (dpath && !stat(dpath,&st)) {
+ if (!(mapinfo = slbt_map_file(
+ AT_FDCWD,dpath,
+ SLBT_MAP_INPUT)))
+ return slbt_exec_link_exit(
+ depsmeta,
+ SLBT_SYSTEM_ERROR(dctx));
+
+ if (!(strncmp(lib,".libs/",6))) {
+ *aarg++ = "-L.libs";
+ lib[1] = 0;
+ } else if ((base = strrchr(lib,'/'))) {
+ if (base - lib == 5) {
+ if (!(strncmp(&base[-5],".libs/",6)))
+ base -= 4;
+
+ } else if (base - lib >= 6) {
+ if (!(strncmp(&base[-6],"/.libs/",7)))
+ base -= 6;
}
- if (ferror(fdeps)) {
- free(depsmeta->altv);
- free(depsmeta->args);
- fclose(fdeps);
+ *base = 0;
+ } else {
+ lib[0] = '.';
+ lib[1] = 0;
+ }
+ while (mapinfo->mark < mapinfo->cap) {
+ if (slbt_mapped_readline(dctx,mapinfo,darg,size))
return slbt_exec_link_exit(
depsmeta,
- SLBT_FILE_ERROR(dctx));
- } else {
- fclose(fdeps);
- }
- } else if (freqd) {
- free(depsmeta->altv);
- free(depsmeta->args);
+ SLBT_NESTED_ERROR(dctx));
- return slbt_exec_link_exit(
- depsmeta,
- SLBT_CUSTOM_ERROR(dctx,SLBT_ERR_LINK_FREQ));
+ *aarg++ = darg;
+ mark = darg;
+
+ dlen = strlen(darg);
+ size -= dlen;
+ darg += dlen;
+ darg[-1] = 0;
+
+ /* handle -L... as needed */
+ if ((mark[0] == '-')
+ && (mark[1] == 'L')
+ && (mark[2] != '/')) {
+ if (strlen(mark) >= sizeof(depdir) - 1)
+ return slbt_exec_link_exit(
+ depsmeta,
+ SLBT_BUFFER_ERROR(dctx));
+
+ darg = mark;
+ strcpy(depdir,&mark[2]);
+ sprintf(darg,"-L%s/%s",lib,depdir);
+
+ darg += strlen(darg);
+ darg++;
+ }
}
}
}