summaryrefslogtreecommitdiff
path: root/src/helper
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2016-10-24 16:41:54 -0400
committermidipix <writeonce@midipix.org>2016-11-11 00:22:50 -0500
commitb183d1ada2b4db899179e1865d4248f8e950a1ca (patch)
tree26e5b10acfd938ebd3b74c41f40d68d01e8a6a2c /src/helper
parent99b875dda2bc51ebc832fb9e380d3bdcc1097c8f (diff)
downloadmdso-b183d1ada2b4db899179e1865d4248f8e950a1ca.tar.bz2
mdso-b183d1ada2b4db899179e1865d4248f8e950a1ca.tar.xz
helper api: renamed mdso_create_output() --> mdso_create_asm_source().
Diffstat (limited to 'src/helper')
-rw-r--r--src/helper/mdso_create_asm_source.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/helper/mdso_create_asm_source.c b/src/helper/mdso_create_asm_source.c
new file mode 100644
index 0000000..0d02c12
--- /dev/null
+++ b/src/helper/mdso_create_asm_source.c
@@ -0,0 +1,47 @@
+/****************************************************************/
+/* mdso: midipix dso scavenger */
+/* Copyright (C) 2015--2016 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"
+
+FILE * mdso_create_asm_source(
+ const struct mdso_driver_ctx * dctx,
+ const char * asmname)
+{
+ struct mdso_driver_ctx_impl * ictx;
+ uintptr_t addr;
+ int fdout;
+ FILE * fout;
+
+ 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) {
+ MDSO_SYSTEM_ERROR(dctx);
+ return 0;
+ }
+
+ if (!(fout = fdopen(fdout,"w"))) {
+ close(fdout);
+ MDSO_SYSTEM_ERROR(dctx);
+ return 0;
+ }
+
+ return fout;
+}