diff options
| author | Vedang Manerikar <ved.manerikar@gmail.com> | 2022-05-11 21:45:21 -0400 |
|---|---|---|
| committer | Vedang Manerikar <ved.manerikar@gmail.com> | 2022-05-11 21:45:21 -0400 |
| commit | fedd930a09a497c03df3ce5204ccbd80da724662 (patch) | |
| tree | 71dc3eb02c66a82ae5b3a595f1395860f0b0b8e6 | |
| parent | 37bbe861755bc60c7cc333359fee3e2a5d919c77 (diff) | |
Revert "Use mkstemp instead of tempnam"
This reverts commit 37bbe861755bc60c7cc333359fee3e2a5d919c77.
As explained by @ShuguangSun (re: testing the change on Windows) on
> Sorry. It is my fault. The issue is still there. The different is
> that the temp dir is created now. However, it reports "Unable to
> create temporary file".
Reopens: #110
| -rw-r--r-- | server/epdfinfo.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/server/epdfinfo.c b/server/epdfinfo.c index 906bdb4..3e0e7c1 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[] = P_tmpdir "/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; } |
