[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/pdf-tools 8ee31220a6 1/2: Revert "Use mkstemp instead of t
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/pdf-tools 8ee31220a6 1/2: Revert "Use mkstemp instead of tempnam" |
Date: |
Mon, 9 May 2022 21:58:34 -0400 (EDT) |
branch: elpa/pdf-tools
commit 8ee31220a6ae3e41549bfffca7a89c481d270004
Author: Vedang Manerikar <ved.manerikar@gmail.com>
Commit: Vedang Manerikar <ved.manerikar@gmail.com>
Revert "Use mkstemp instead of tempnam"
This reverts commit d63a1e7d87f9b0a19209f2eeb170bcf64612aa2f.
In d63a1e7, @JunyuanChen fixed a long standing compilation warning by
replacing `tempnam` with `mkstemp` in `epdfinfo`. However, the
`mkstemp` implementation does not work correctly on MS
Windows (probably because the path template is "wrong" for Windows).
I am reverting the commit and opening a new issue #110 to track the
correct implementation of `mkstemp` (or equivalent) on MS Windows.
It would also be great to add a test against Windows CI to open a PDF
and check that the operation completes successfully.
Closes: #101
---
server/epdfinfo.c | 29 ++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)
diff --git a/server/epdfinfo.c b/server/epdfinfo.c
index 95a7f1628a..3e0e7c1166 100644
--- a/server/epdfinfo.c
+++ b/server/epdfinfo.c
@@ -35,7 +35,6 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
-#include <unistd.h>
#include <errno.h>
#include <png.h>
#include <math.h>
@@ -347,18 +346,26 @@ strchomp (char *str)
static char*
mktempfile()
{
- char template[] = "/tmp/epdfinfoXXXXXX";
- char *filename = malloc(sizeof(template));
- memcpy(filename, template, sizeof(template));
- int fd = mkstemp(filename);
- if (fd == -1)
+ char *filename = NULL;
+ int tries = 3;
+ while (! filename && tries-- > 0)
{
- fprintf (stderr, "Unable to create tempfile");
- free(filename);
- filename = NULL;
+
+ 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;
+ }
+ }
}
- else
- close(fd);
+ if (! filename)
+ fprintf (stderr, "Unable to create tempfile");
return filename;
}