summaryrefslogtreecommitdiffhomepage
path: root/src/helper/mdso_create_output.c
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2017-02-08 01:08:41 -0500
committermidipix <writeonce@midipix.org>2017-02-08 01:19:09 -0500
commit00a88c01dc20c33da1936600d46974d460a23cc4 (patch)
tree2b0de22c0b68520e9504b566fce23d67ab16b05b /src/helper/mdso_create_output.c
parenta75141e458ef5b5016961afcb789ee8d2cee2584 (diff)
downloadmdso-00a88c01dc20c33da1936600d46974d460a23cc4.tar.bz2
mdso-00a88c01dc20c33da1936600d46974d460a23cc4.tar.xz
project: source tree: tidy up.
Diffstat (limited to 'src/helper/mdso_create_output.c')
-rw-r--r--src/helper/mdso_create_output.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/helper/mdso_create_output.c b/src/helper/mdso_create_output.c
new file mode 100644
index 0000000..b152697
--- /dev/null
+++ b/src/helper/mdso_create_output.c
@@ -0,0 +1,66 @@
+/****************************************************************/
+/* mdso: midipix dso scavenger */
+/* Copyright (C) 2015--2017 Z. Gilboa */
+/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */
+/****************************************************************/
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <stddef.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#include <mdso/mdso.h>
+#include "mdso_driver_impl.h"
+#include "mdso_errinfo_impl.h"
+
+static FILE * mdso_create_output(
+ const struct mdso_driver_ctx * dctx,
+ const char * name)
+{
+ struct mdso_driver_ctx_impl * ictx;
+ uintptr_t addr;
+ int fdout;
+ FILE * fout;
+
+ addr = (uintptr_t)dctx - offsetof(struct mdso_driver_ctx_impl,ctx);
+ ictx = (struct mdso_driver_ctx_impl *)addr;
+
+ if ((fdout = openat(ictx->fddst,name,
+ O_CREAT|O_TRUNC|O_WRONLY|O_NOCTTY|O_NOFOLLOW,
+ S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0) {
+ MDSO_SYSTEM_ERROR(dctx);
+ return 0;
+ }
+
+ if (!(fout = fdopen(fdout,"w"))) {
+ close(fdout);
+ MDSO_SYSTEM_ERROR(dctx);
+ return 0;
+ }
+
+ return fout;
+}
+
+FILE * mdso_create_asm_source(
+ const struct mdso_driver_ctx * dctx,
+ const char * asmname)
+{
+ if (!dctx->cctx->dstdir)
+ return stdout;
+
+ return mdso_create_output(dctx,asmname);
+}
+
+FILE * mdso_create_object(
+ const struct mdso_driver_ctx * dctx,
+ const char * objname)
+{
+ if (!dctx->cctx->dstdir) {
+ MDSO_CUSTOM_ERROR(dctx,MDSO_ERR_INVALID_DSTDIR);
+ return 0;
+ }
+
+ return mdso_create_output(dctx,objname);
+}