diff options
author | midipix <writeonce@midipix.org> | 2018-06-28 11:23:29 -0400 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2018-06-29 01:37:43 -0400 |
commit | c100d16db531b5ff2e252461ac50c63334108a22 (patch) | |
tree | 982a703b40d5c1e0ad8cde133bc7c7158cf7079e /src/helper/slbt_archive_import.c | |
parent | 05ea52ac8079f8acc8d68524401f7afae4c89209 (diff) | |
download | slibtool-c100d16db531b5ff2e252461ac50c63334108a22.tar.bz2 slibtool-c100d16db531b5ff2e252461ac50c63334108a22.tar.xz |
helper interfaces: re-implemented slbt_archive_import() w. pure fdio.
Diffstat (limited to 'src/helper/slbt_archive_import.c')
-rw-r--r-- | src/helper/slbt_archive_import.c | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/src/helper/slbt_archive_import.c b/src/helper/slbt_archive_import.c index a4c58e7..84bef92 100644 --- a/src/helper/slbt_archive_import.c +++ b/src/helper/slbt_archive_import.c @@ -14,6 +14,7 @@ #include <slibtool/slibtool.h> #include "slibtool_spawn_impl.h" +#include "slibtool_dprintf_impl.h" #include "slibtool_symlink_impl.h" #include "slibtool_readlink_impl.h" #include "slibtool_errinfo_impl.h" @@ -79,24 +80,28 @@ int slbt_archive_import( char * dstarchive, char * srcarchive) { - int ret; pid_t pid; pid_t rpid; int fd[2]; - FILE * fout; char * dst; char * src; + char * fmt; char mridst [L_tmpnam]; char mrisrc [L_tmpnam]; char program[PATH_MAX]; + /* not needed? */ if (slbt_symlink_is_a_placeholder(srcarchive)) return 0; - if ((size_t)snprintf(program,sizeof(program),"%s", - dctx->cctx->host.ar) >= sizeof(program)) + /* program */ + if ((size_t)snprintf(program,sizeof(program), + "%s", + dctx->cctx->host.ar) + >= sizeof(program)) return SLBT_BUFFER_ERROR(dctx); + /* fork */ if (pipe(fd)) return SLBT_SYSTEM_ERROR(dctx); @@ -106,36 +111,31 @@ int slbt_archive_import( return SLBT_SYSTEM_ERROR(dctx); } + /* child */ if (pid == 0) slbt_archive_import_child( program, fd); + /* parent */ + close(fd[0]); + ectx->pid = pid; dst = slbt_mri_argument(dstarchive,mridst); src = slbt_mri_argument(srcarchive,mrisrc); + fmt = "OPEN %s\n" + "ADDLIB %s\n" + "SAVE\n" + "END\n"; - if ((fout = fdopen(fd[1],"a"))) { - ret = (fprintf( - fout, - "OPEN %s\n" - "ADDLIB %s\n" - "SAVE\n" - "END\n", - dst, - src) < 0) - ? SLBT_SYSTEM_ERROR(dctx) - : 0; - - fclose(fout); - close(fd[0]); - } else { - ret = SLBT_SYSTEM_ERROR(dctx); - close(fd[0]); + if (slbt_dprintf(fd[1],fmt,dst,src) < 0) { close(fd[1]); + return SLBT_SYSTEM_ERROR(dctx); } + close(fd[1]); + rpid = waitpid( pid, &ectx->exitcode, @@ -147,6 +147,6 @@ int slbt_archive_import( if (src == mrisrc) unlink(src); - return ret || (rpid != pid) || ectx->exitcode - ? SLBT_CUSTOM_ERROR(dctx,SLBT_ERR_ARCHIVE_IMPORT) : 0; + return (rpid == pid) && (ectx->exitcode == 0) + ? 0 : SLBT_CUSTOM_ERROR(dctx,SLBT_ERR_ARCHIVE_IMPORT); } |