diff options
Diffstat (limited to 'server')
| -rw-r--r-- | server/epdfinfo.c | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/server/epdfinfo.c b/server/epdfinfo.c index 061df61..7faeb89 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> @@ -338,6 +339,11 @@ strchomp (char *str) return str; } +#if HAVE_W32 +#define MKTEMP_SEPARATOR "\\" +#else +#define MKTEMP_SEPARATOR "/" +#endif /** * Create a new, temporary file and returns its name. * @@ -346,26 +352,18 @@ strchomp (char *str) static char* mktempfile() { - char *filename = NULL; - int tries = 3; - while (! filename && tries-- > 0) + char template[] = P_tmpdir MKTEMP_SEPARATOR "epdfinfo_XXXXXX"; + 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; } |
