From 3895afa953a49e842fa99fa08842268d6f58aae9 Mon Sep 17 00:00:00 2001 From: midipix Date: Tue, 3 May 2016 12:42:43 -0400 Subject: internals: slbt_mkdir(): initial implementation and integration. --- project/headers.mk | 1 + src/internal/slibtool_mkdir_impl.h | 25 +++++++++++++++++++++++++ src/logic/slbt_exec_compile.c | 15 +++++---------- src/logic/slbt_exec_link.c | 15 +++++---------- 4 files changed, 36 insertions(+), 20 deletions(-) create mode 100644 src/internal/slibtool_mkdir_impl.h diff --git a/project/headers.mk b/project/headers.mk index eacad87..bca122f 100644 --- a/project/headers.mk +++ b/project/headers.mk @@ -6,6 +6,7 @@ INTERNAL_HEADERS = \ $(PROJECT_DIR)/src/internal/argv/argv.h \ $(PROJECT_DIR)/src/internal/$(PACKAGE)_driver_impl.h \ $(PROJECT_DIR)/src/internal/$(PACKAGE)_install_impl.h \ + $(PROJECT_DIR)/src/internal/$(PACKAGE)_mkdir_impl.h \ $(PROJECT_DIR)/src/internal/$(PACKAGE)_readlink_impl.h \ $(PROJECT_DIR)/src/internal/$(PACKAGE)_spawn_impl.h \ $(PROJECT_DIR)/src/internal/$(PACKAGE)_symlink_impl.h \ diff --git a/src/internal/slibtool_mkdir_impl.h b/src/internal/slibtool_mkdir_impl.h new file mode 100644 index 0000000..9be237b --- /dev/null +++ b/src/internal/slibtool_mkdir_impl.h @@ -0,0 +1,25 @@ +/*******************************************************************/ +/* slibtool: a skinny libtool implementation, written in C */ +/* Copyright (C) 2016 Z. Gilboa */ +/* Released under the Standard MIT License; see COPYING.SLIBTOOL. */ +/*******************************************************************/ + +#include +#include + +#ifndef O_DIRECTORY +#define O_DIRECTORY 0 +#endif + +static inline int slbt_mkdir(const char * path) +{ + int fdlibs; + + if ((fdlibs = open(path,O_DIRECTORY)) >= 0) + close(fdlibs); + else if ((errno != ENOENT) || mkdir(path,0777)) + if (errno != EEXIST) + return -1; + + return 0; +} diff --git a/src/logic/slbt_exec_compile.c b/src/logic/slbt_exec_compile.c index c5c3e70..4a75270 100644 --- a/src/logic/slbt_exec_compile.c +++ b/src/logic/slbt_exec_compile.c @@ -12,6 +12,7 @@ #include #include "slibtool_spawn_impl.h" +#include "slibtool_mkdir_impl.h" static int slbt_exec_compile_remove_file( const struct slbt_driver_ctx * dctx, @@ -35,7 +36,6 @@ int slbt_exec_compile( struct slbt_exec_ctx * ectx) { int ret; - int fdlibs; FILE * fout; struct slbt_exec_ctx * actx = 0; const struct slbt_source_version * verinfo; @@ -57,16 +57,11 @@ int slbt_exec_compile( return -1; /* .libs directory */ - if (dctx->cctx->drvflags & SLBT_DRIVER_SHARED) { - if ((fdlibs = open(ectx->ldirname,O_DIRECTORY)) >= 0) - close(fdlibs); - else if ((errno != ENOENT) || mkdir(ectx->ldirname,0777)) { - if (errno != EEXIST) { - slbt_free_exec_ctx(actx); - return -1; - } + if (dctx->cctx->drvflags & SLBT_DRIVER_SHARED) + if (slbt_mkdir(ectx->ldirname)) { + slbt_free_exec_ctx(actx); + return -1; } - } /* compile mode */ ectx->program = ectx->compiler; diff --git a/src/logic/slbt_exec_link.c b/src/logic/slbt_exec_link.c index 847bc95..d964df0 100644 --- a/src/logic/slbt_exec_link.c +++ b/src/logic/slbt_exec_link.c @@ -14,6 +14,7 @@ #include #include "slibtool_spawn_impl.h" +#include "slibtool_mkdir_impl.h" #include "slibtool_readlink_impl.h" #include "slibtool_symlink_impl.h" @@ -995,7 +996,6 @@ int slbt_exec_link( struct slbt_exec_ctx * ectx) { int ret; - int fdlibs; const char * output; char * dot; FILE * fout; @@ -1062,16 +1062,11 @@ int slbt_exec_link( dot = strrchr(output,'.'); /* .libs directory */ - if (dctx->cctx->drvflags & SLBT_DRIVER_SHARED) { - if ((fdlibs = open(ectx->ldirname,O_DIRECTORY)) >= 0) - close(fdlibs); - else if ((errno != ENOENT) || mkdir(ectx->ldirname,0777)) { - if (errno != EEXIST) { - slbt_free_exec_ctx(actx); - return -1; - } + if (dctx->cctx->drvflags & SLBT_DRIVER_SHARED) + if (slbt_mkdir(ectx->ldirname)) { + slbt_free_exec_ctx(actx); + return -1; } - } /* non-pic libfoo.a */ if (dot && !strcmp(dot,".a")) -- cgit v1.2.3