Commit fc6b939066f211b99eed3c8111e446ec95d51ca6

Anthony Green 2022-09-19T06:42:29

Standardize temp exec file creation

diff --git a/src/closures.c b/src/closures.c
index 3b7a0ac..9aafbec 100644
--- a/src/closures.c
+++ b/src/closures.c
@@ -763,7 +763,7 @@ open_temp_exec_file_opts_next (void)
 
 /* Return a file descriptor of a temporary zero-sized file in a
    writable and executable filesystem.  */
-static int
+int
 open_temp_exec_file (void)
 {
   int fd;
diff --git a/src/tramp.c b/src/tramp.c
index 9cec81e..0938c08 100644
--- a/src/tramp.c
+++ b/src/tramp.c
@@ -253,20 +253,14 @@ ffi_tramp_get_libffi (void)
 
 #if defined (__linux__) || defined (__CYGWIN__)
 
-#if defined HAVE_MKSTEMP
-
 static int
 ffi_tramp_get_temp_file (void)
 {
-  char template[12] = "/tmp/XXXXXX";
   ssize_t count;
 
   tramp_globals.offset = 0;
-  tramp_globals.fd = mkstemp (template);
-  if (tramp_globals.fd == -1)
-    return 0;
+  tramp_globals.fd = open_temp_exec_file ();
 
-  unlink (template);
   /*
    * Write the trampoline code table into the temporary file and allocate a
    * trampoline table to make sure that the temporary file can be mapped.
@@ -280,24 +274,6 @@ ffi_tramp_get_temp_file (void)
   return 0;
 }
 
-#else /* !defined HAVE_MKSTEMP */
-
-/*
- * TODO:
- * src/closures.c contains code for finding temp file that has EXEC
- * permissions. May be, some of that code can be shared with static
- * trampolines.
- */
-static int
-ffi_tramp_get_temp_file (void)
-{
-  tramp_globals.offset = 0;
-  tramp_globals.fd = -1;
-  return 0;
-}
-
-#endif /* defined HAVE_MKSTEMP */
-
 #endif /* defined (__linux__) || defined (__CYGWIN__) */
 
 /* ------------------------ OS-specific Initialization ----------------------*/