diff options
| author | Vedang Manerikar <ved.manerikar@gmail.com> | 2022-05-11 15:39:25 -0400 |
|---|---|---|
| committer | Vedang Manerikar <ved.manerikar@gmail.com> | 2022-05-11 15:45:47 -0400 |
| commit | 37bbe861755bc60c7cc333359fee3e2a5d919c77 (patch) | |
| tree | 2050ea3646e757a474f4d3f1ca533cfddc9053cb /server | |
| parent | ab61b0472980200f52e2e23782bc07255baebe72 (diff) | |
Use mkstemp instead of tempnam
This reverts commit 8ee31220a6ae3e41549bfffca7a89c481d270004 and
brings in @JunyuanChen's change once again.
We modify the commit to fix the problem on Windows by changing the
code as follows:
--- a/server/epdfinfo.c
+++ b/server/epdfinfo.c
@@ -347,6 +347,6 @@
static char*
mktempfile()
{
- char template[] = "/tmp/epdfinfoXXXXXX";
+ char template[] = P_tmpdir "/epdfinfoXXXXXX";
char *filename = malloc(sizeof(template));
memcpy(filename, template, sizeof(template));
This works correctly for Windows (as confirmed by @ShuguangSun),
Mac (tested by @vedang) and Linux (tested by @Junyuanchen)
Relates to: #101, #94
Closes: #110
Diffstat (limited to 'server')
| -rw-r--r-- | server/epdfinfo.c | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/server/epdfinfo.c b/server/epdfinfo.c index 3e0e7c1..906bdb4 100644 --- a/server/epdfinfo.c +++ b/server/epdfinfo.c @@ -35,6 +35,7 @@ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> +#include <unistd.h> #include <errno.h> #include <png.h> #include <math.h> @@ -346,26 +347,18 @@ strchomp (char *str) static char* mktempfile() { - char *filename = NULL; - int tries = 3; - while (! filename && tries-- > 0) + char template[] = P_tmpdir "/epdfinfoXXXXXX"; + char *filename = malloc(sizeof(template)); + memcpy(filename, template, sizeof(template)); + int fd = mkstemp(filename); + if (fd == -1) { - - filename = tempnam(NULL, "epdfinfo"); - if (filename) - { - int fd = open(filename, O_CREAT | O_EXCL | O_RDONLY, S_IRWXU); - if (fd > 0) - close (fd); - else - { - free (filename); - filename = NULL; - } - } + fprintf (stderr, "Unable to create tempfile"); + free(filename); + filename = NULL; } - if (! filename) - fprintf (stderr, "Unable to create tempfile"); + else + close(fd); return filename; } |
