summaryrefslogtreecommitdiff
path: root/src/output
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2015-12-21 07:33:01 -0500
committermidipix <writeonce@midipix.org>2016-11-11 00:22:30 -0500
commit3b42f99f60194a4afea5bf04b9f1439ffde4d666 (patch)
treeef80f8e1af623dc96846b96cde79ed44a77b6c91 /src/output
parent938a475adc16f90139cb6227f3e54e6aa743d528 (diff)
downloadmdso-3b42f99f60194a4afea5bf04b9f1439ffde4d666.tar.bz2
mdso-3b42f99f60194a4afea5bf04b9f1439ffde4d666.tar.xz
mdso_create_output(): initial implementation.
Diffstat (limited to 'src/output')
-rw-r--r--src/output/mdso_create_output.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/output/mdso_create_output.c b/src/output/mdso_create_output.c
new file mode 100644
index 0000000..3ecde61
--- /dev/null
+++ b/src/output/mdso_create_output.c
@@ -0,0 +1,37 @@
+/****************************************************************/
+/* mdso: midipix dso scavenger */
+/* Copyright (C) 2015 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"
+
+FILE * mdso_create_output(
+ const struct mdso_driver_ctx * dctx,
+ const char * asmname)
+{
+ struct mdso_driver_ctx_impl * ictx;
+ uintptr_t addr;
+ int fdout;
+
+ if (!dctx->cctx->dstdir)
+ return stdout;
+
+ addr = (uintptr_t)dctx - offsetof(struct mdso_driver_ctx_impl,ctx);
+ ictx = (struct mdso_driver_ctx_impl *)addr;
+
+ if ((fdout = openat(ictx->fddst,asmname,
+ O_CREAT|O_TRUNC|O_WRONLY|O_NOCTTY|O_NOFOLLOW,
+ S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0)
+ return 0;
+
+ return fdopen(fdout,"w");
+}