summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/internal/tpax_tmpfile_impl.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/internal/tpax_tmpfile_impl.c b/src/internal/tpax_tmpfile_impl.c
index 56d5c92..9dd9d40 100644
--- a/src/internal/tpax_tmpfile_impl.c
+++ b/src/internal/tpax_tmpfile_impl.c
@@ -5,12 +5,16 @@
/**************************************************************/
#define _GNU_SOURCE
+#include <time.h>
#include <fcntl.h>
#include <limits.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
+#include <inttypes.h>
+
+#define PPRIX64 "%"PRIx64
/* mkostemp might be guarded by non-standard macros */
/* unless HAVE_NO_MKOSTEMP, assume it is available */
@@ -54,8 +58,8 @@ static int tpax_mkostemp(char * tmplate)
int tpax_tmpfile(void)
{
int fd;
- unsigned seed;
- char tmplate[64];
+ void * addr;
+ char tmplate[128];
/* try with __fs_tmpfile() */
if ((fd = tpax_tmpfile_by_framework()) >= 0)
@@ -66,10 +70,18 @@ int tpax_tmpfile(void)
return fd;
/* fallback to mk{o}stemp */
- seed = getpid();
+ addr = tmplate;
memset(tmplate,0,sizeof(tmplate));
- snprintf(tmplate,sizeof(tmplate),"/tmp/tpax_%d_%d_%d_XXXXXXXXXXXX",
- getppid(),getpid(),rand_r(&seed));
+ snprintf(tmplate,sizeof(tmplate),
+ "/tmp/"
+ ".tpax.tmpfile"
+ ".time."PPRIX64
+ ".salt.%p"
+ ".pid.%d"
+ ".XXXXXXXXXXXX",
+ time(0),
+ addr,
+ getpid());
return tpax_mkostemp(tmplate);
}